我有这段代码,似乎有问题,我无法让它工作。有趣的是,如果我将/§0([^§]*)/
to/§2([^§]*)/
或/§1([^§]*)/
id 替换为挑选的作品,但其余的则不然。
<?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>');
//echo preg_replace($suchmuster, $ersetzung, $zeichenkette);
echo $text;
echo '<br />';
echo preg_replace(key($color_code), array_shift($color_code), $text);
?>