3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function highlight($text, $words) { preg_match_all ( '~[a-zA-Z_']+~', $words, $m ); if (! $m) return $text; $re = '~\\b(' . implode ( '|', $m [0] ) . ')\\b~i'; return preg_replace ( $re, '<em>$0</em>', $text ); } $text = "this is Mechanic's test"; $word = "Mechanic's"; echo highlight($text,$word); $text = 'this is Mechanic"s test'; $word = 'Mechanic"s'; echo "\n".highlight($text,$word); $text = 'this is Mechanics test'; $word = 'mech'; echo "\n".highlight($text,$word); // echo "\n".str_replace($word,"<em>$word</em>",$text) ;
based on FvP7E
Output for 7.0.0 - 7.1.7
Parse error: syntax error, unexpected ']', expecting ',' or ')' in /in/X0YmB on line 3
Process exited with code 255.
Output for hhvm-3.15.4
Fatal error: Uncaught Error: syntax error, unexpected ']', expecting ')' in /in/X0YmB:3 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected ']' in /in/X0YmB on line 3
Process exited with code 255.