3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = "§6Title §f- §1Bla§2Bli§4Blu"; $color_code = array( '/§0([^§]*)/' => '<span style="color: #000;">' . strtoupper("$1") . '</span>', '/§1([^§]*)/' => '<span style="color: #0000AA;">' . strtoupper("$1") . '</span>', '/§2([^§]*)/' => '<span style="color: #00AA00;">' . strtoupper("$1") . '</span>', '/§3([^§]*)/' => '<span style="color: green;">' . strtoupper("$1") . '</span>', '/§4([^§]*)/' => '<span style="color: green;">' . strtoupper("$1") . '</span>', '/§5([^§]*)/' => '<span style="color: green;">' . strtoupper("$1") . '</span>', '/§6([^§]*)/' => '<span style="color: green;">' . strtoupper("$1") . '</span>', '/§7([^§]*)/' => '<span style="color: green;">' . strtoupper("$1") . '</span>', '/§8([^§]*)/' => '<span style="color: green;">' . strtoupper("$1") . '</span>', '/§9([^§]*)/' => '<span style="color: green;">' . strtoupper("$1") . '</span>', '/§a([^§]*)/' => '<span style="color: green;">' . strtoupper("$1") . '</span>', '/§b([^§]*)/' => '<span style="color: green;">' . strtoupper("$1") . '</span>', '/§c([^§]*)/' => '<span style="color: green;">' . strtoupper("$1") . '</span>', '/§d([^§]*)/' => '<span style="color: blue;">' . strtoupper("$1") . '</span>', '/§e([^§]*)/' => '<span style="color: blue;">' . strtoupper("$1") . '</span>', '/§f([^§]*)/' => '<span style="color: blue;">' . strtoupper("$1") . '</span>'); while ($color_code) { $text = preg_replace(key($color_code), array_shift($color_code), $text); } echo $text;
Output for 8.2.0 - 8.2.27, 8.3.0 - 8.3.16, 8.4.1 - 8.4.3
<span style="color: green;">Title </span><span style="color: blue;">- <span style="color: #0000AA;">Bla</span><span style="color: #00AA00;">Bli</span><span style="color: green;">Blu</span></span>

preferences:
46.33 ms | 406 KiB | 5 Q