@ 2017-07-10T10:15:28Z <?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 Mechanics test Mechanics test test test test Mechanics';
$word = 'Mech';
echo "\n".highlight($text,$word);
echo "\n".str_replace($word,"<em>$word</em>",$text) ;
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 5.6.0 - 5.6.40 , 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.7 this is <em>Mechanic's</em> test
this is <em>Mechanic</em>"<em>s</em> test
this is Mechanics test Mechanics test Mechanics test test test test Mechanics
this is <em>Mech</em>anics test <em>Mech</em>anics test <em>Mech</em>anics test test test test <em>Mech</em>anics preferences:dark mode live preview
253.77 ms | 404 KiB | 289 Q