检查是否存在并替换


Check if exists and replace

$server['s']['name'] = "§4Hello world i'm §1Mafios_X";
//
$name = $server['s']['name'];

我如何检查$name是否存在,$4<font color="red">中改变它,并在另一个$4(或一些$)之前关闭</font>标签,如果不存在任何其他$,在$name完成后关闭。

我怎么做这个?

如果我理解你的话

if(preg_match('/(§4)/', $name)) // if '§4' exists in $name it will go into conditional block
{
   $name = preg_replace('/(§4)/', '/<font color="red">$1<'/font>/', $str); // we replace it 
}
else
{
  //it doesn't exists
   $name.="</font>"; // we close with font tag
}

基本上都是关于preg_replace('/(§4)/', '/<font color="red">$1<'/font>/', $str);的它会将每个§4更改为<font color="red">§4<'/font>