替换 眼镜 的时候,要求 眼镜 前后不能有 > < 这种符号,如果有,认为被替换过了,这样应该能够区别吧……
具体请楼上或楼下写正则……

解决方案 »

  1.   

    替换这个时<small>眼镜 </small> 加个判断 
      

  2.   

    $a1=array("/有色眼镜/","/眼镜[^<]/"); 
    $a2=array("<strong>有色眼镜</strong>","<small>眼镜</small>");
    preg_replace($a1,$a2,$content);试试这个看行不行 
      

  3.   


    $a1=array("/眼镜/","/有色<small>眼镜<\/small>/"); 
    $a2=array("<small>眼镜</small>","<strong>有色眼镜</strong>"); 
    $content="我喜欢有色眼镜,其他的眼镜不太喜欢!"; 
    echo preg_replace($a1,$a2,$content); 
      

  4.   

    <?php
    $a1=array("有色眼镜","眼镜"); 
    $a2=array(" <strong>有色眼镜 </strong>"," <small>眼镜 </small>"); $content="我喜欢有色眼镜,其他的眼镜不太喜欢!";echo str_replace($a1,$a2,$content);
    ?>