3v4l.org

run code in 300+ PHP versions simultaneously
<?php function highlight($needle, $haystack, $respect, $highlightStart, $highlightEnd) { $replacer = static function ($matches) use ($respect, $highlightStart, $highlightEnd) { return $highlightStart . preg_replace('([^' . $respect . ']+)', $highlightEnd . '$0' . $highlightStart, $matches[0]) . $highlightEnd; }; $needle = str_split($needle); foreach ($needle as &$l) { $l = preg_quote($l); } unset($l); $needle = implode('[^' . $respect . ']*', $needle); return preg_replace_callback('(' . $needle . ')', $replacer, $haystack); } echo highlight('1234', '(123) 456-7890', '0-9', '<b>', '</b>');
Output for git.master, git.master_jit, rfc.property-hooks
(<b>123</b>) <b>4</b>56-7890

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:
46.45 ms | 401 KiB | 8 Q