3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Here is a url that contains some regex strings (see the (\d+) twice)? // I want to replace each one individually, using a regex of the regex, with the contents of the $params array // Final result should be http://whatever.com/en-GB/companies/8556/blah/502034/link/etc // Note they're in the correct order! $expectedUrl = "http://whatever.com/en-GB/companies/(\d+)/blah/(\d+)/link/etc"; preg_match_all('#\((.*?)\)#', $expectedUrl, $matches); $search = $matches[0]; $params = array(8556, "?"); foreach (array_combine($params, $search) as $value => $key) { $split = str_split($key); foreach ($split as &$char) { if ($char !== "\\") $char = "\\" . $char; } $split = implode("", $split); $expectedUrl = preg_replace("/".$split."/", $value, $expectedUrl, 1); } var_dump($expectedUrl);
Output for git.master, git.master_jit, rfc.property-hooks
string(56) "http://whatever.com/en-GB/companies/8556/blah/?/link/etc"

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