$preg = "/(?<!for|to) iphone/i";//排除iphone 单词前面带 for或者to的后,将iphone替换成红色字体 $str = "Bumper Frame TPU Silicone Case For IPhone 5 5S PromotionHot Sell For Apple IPhone 5 5S Exquisitely Designed"; $str = preg_replace($preg,‘<font color="red"> Iphone </font>‘,$str); var_dump($str);