3v4l.org

run code in 500+ PHP versions simultaneously
<?php function getRegexUri(string $uri): string { return '#^' . \preg_replace_callback( '/\/\{(\??)([a-zA-Z_][a-zA-Z0-9_]*)(?::([^}]+)|<([^>]+)>)?}/', function (array $matches): string { $regex = $matches[3] ?? null; $type = $matches[4] ?? null; if ($regex === '') { $regex = null; } $pattern = $regex ?? $this->patterns->get($type ?? '')->regex ?? '[^/]+'; $segment = '(?<' . $matches[2] . '>' . $pattern . ')'; return $matches[1] === '?' ? '(?:/' . $segment . ')?' : '/' . $segment; }, $uri, ) . '$#'; } $v = '/test-http-{code:\d+}/'; var_dump(getRegexUri($v));
Output for rfc.property-hooks, git.master, git.master_jit
string(26) "#^/test-http-{code:\d+}/$#"

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:
62.69 ms | 2702 KiB | 4 Q