3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = '§f§lWORDHERE'; $replacements = [ '§f' => '<span style="color: white;">$0</span>', '§l' => '<b>$0</b>', ]; if (preg_match('/^(?<flags>(?:§[a-z])+)(?<string>.*)/iu', $str, $matches)) { $str_res = $matches['string']; foreach (mb_str_split($matches['flags'], 2) as $flag) { $str_res = preg_replace('/.+/', $replacements[$flag], $str_res); } echo $str_res; }

preferences:
27.97 ms | 406 KiB | 5 Q