3v4l.org

run code in 300+ PHP versions simultaneously
<?php // I have this string to start: $input = "eskimo> __adrian: it's for matching nicks in irc"; // I want to turn it into this string: $expected = "%eskimo%> %__adrian%: it's for matching nicks in irc"; $nicks = ["eskimo", "__adrian"]; $result = mark($input, ...$nicks); function mark(string $message, string ...$nicks) { $marks = array_map(fn($n) => "%{$n}%", $nicks); return strtr($message, array_combine($nicks, $marks)); } echo $result; assert($result === $expected);
Output for git.master, git.master_jit, rfc.property-hooks
%eskimo%> %__adrian%: it's for matching nicks in irc

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