这个应用主要是用到了递归函数,中英文相同改变参数就行方法如下: function changes($str,$arr){ foreach($arr as $val){ $str=str_replace($val,"<font color='red'>".$val."</font>",$str); @changes($str,$val); }
return $str; } $str = "hello word and so hello good word yes ones"; $arr = array("hello","word"); echo changes($str,$arr);追问