3v4l.org

run code in 300+ PHP versions simultaneously
<?php function convert(string $txt): string { do { $txt = preg_replace_callback_array( [ '~\[([bi])](.*?)\[/\1]~' => fn($m) => sprintf('<%1$s>%2$s</%1$s>', $m[1], $m[2]), '~\[img](.*?)\[/img]~' => 'foo', ], $txt, -1, $count ); } while ($count); return $txt; } function foo(array $m): string { return '<img src="' . $m[1] . '">'; } echo convert("text1 [img]path/src[/img] text2 [b]bold [i]nested string[/i][/b] [img]another/path/to/file[/img] [b]nice[/b] lingering end bbtag [/b] and [b]unclosed");
Output for git.master, git.master_jit, rfc.property-hooks
text1 <img src="path/src"> text2 <b>bold <i>nested string</i></b> <img src="another/path/to/file"> <b>nice</b> lingering end bbtag [/b] and [b]unclosed

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