3v4l.org

run code in 300+ PHP versions simultaneously
<?php function highlight($text, $words) { preg_match_all ( '~[\w\'\"]+~', $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($words,"<em>$words</em>",$text) ;
Output for git.master, git.master_jit, rfc.property-hooks
this is <em>Mechanic's</em> test this is <em>Mechanic"s</em> test this is Mechanics test Warning: Undefined variable $words in /in/7gQT1 on line 25 Warning: Undefined variable $words in /in/7gQT1 on line 25 Deprecated: str_replace(): Passing null to parameter #1 ($search) of type array|string is deprecated in /in/7gQT1 on line 25 this is Mechanics test

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
40.14 ms | 402 KiB | 8 Q