3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php mb_internal_encoding('UTF-8'); $full_string = 'être vivant'; $match = 'vivant'; //) is êtr<strong>e viva</strong>nt echo Foo::highlightTerm($full_string, $match); class Foo{ public static function highlightTerm($full_string, $match){ $full_string_ascii = preg_replace_callback('/[\w]+/ui', array('self', 'callbackHighlightTerm'), $full_string); $match_ascii = preg_replace_callback('/[\w]+/ui', array('self', 'callbackHighlightTerm'), $match); $start = stripos($full_string_ascii, $match_ascii); if($start===FALSE){ return $full_string; }else{ $length = mb_strlen($match); return htmlspecialchars( mb_substr($full_string, 0, $start)) . '<strong>' . htmlspecialchars( mb_substr($full_string, $start, $length) ) . '</strong>' . htmlspecialchars( mb_substr($full_string, $start+$length) ); } } private static function callbackHighlightTerm($matches){ /**/var_dump(preg_replace('/[^\w]/i', '', iconv('UTF-8', 'ASCII//TRANSLIT', $matches[0]))); return preg_replace('/[^\w]/i', '', iconv('UTF-8', 'ASCII//TRANSLIT', $matches[0])); } } ?>
Output for 5.3.4 - 5.5.34, 5.6.7 - 5.6.20, 5.6.28, hhvm-3.12.0, 7.0.0 - 7.0.5, 7.0.12 - 7.1.0
string(3) "tre" string(6) "vivant" string(6) "vivant" être<strong> vivan</strong>t
Output for 7.0.6
Fatal error: Uncaught Error: Call to undefined function iconv() in /in/RMHpX:32 Stack trace: #0 [internal function]: Foo::callbackHighlightTerm(Array) #1 /in/RMHpX(13): preg_replace_callback('/[\\w]+/ui', Array, '\xC3\xAAtre vivant') #2 /in/RMHpX(9): Foo::highlightTerm('\xC3\xAAtre vivant', 'vivant') #3 {main} thrown in /in/RMHpX on line 32
Process exited with code 255.
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.5.35, 5.6.21
Fatal error: Call to undefined function iconv() in /in/RMHpX on line 32
Process exited with code 255.
Output for 5.0.0 - 5.3.3
string(3) "tre" string(6) "vivant" string(6) "vivant" être v<strong>ivant</strong>
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/RMHpX on line 12
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/RMHpX on line 12
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/RMHpX on line 12
Process exited with code 255.