<?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);
%eskimo%> %__adrian%: it's for matching nicks in irc
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
%eskimo%> %__adrian%: it's for matching nicks in irc
Output for 7.3.0 - 7.3.33
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ')' in /in/hMb0Y on line 14
Process exited with code 255.