3v4l.org

run code in 300+ PHP versions simultaneously
<?php function highlight(string $search, string $number): string { $searchBegin = NULL; $searchIndex = 0; $search = str_replace([',', '.'], '', $search); foreach (str_split($number) as $numberIndex => $character) { if ($character == $search[$searchIndex]) { if (is_null($searchBegin)) { $searchBegin = $numberIndex; } $searchIndex++; if ($searchIndex == strlen($search)) { return substr($number, 0, $searchBegin) . '<span style="background: yellow">' . substr($number, $searchBegin, $numberIndex - $searchBegin + 1) . '</span>' . highlight($search, substr($number, $numberIndex + 1)); } } elseif (!in_array($character, [',', '.'])) { $searchBegin = NULL; $searchIndex = 0; } } return $number; } echo highlight('1234', '12,341,234.00') . PHP_EOL;
Output for git.master_jit, git.master, rfc.property-hooks
<span style="background: yellow">12,34</span><span style="background: yellow">1,234</span>.00

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:
27.91 ms | 405 KiB | 5 Q