我对PHP的正则表达式不太熟悉 在使用eregi_replace()函数时发现带有()的字符串不能进行替换,比如 将 DIN 1693(Pt.2)-1997 加粗 使用 $str='din 1693(Pt.2)-1997' eregi_replace($str,"<strong>".$str."</strong>",$str); 最后因为字符串中含有括号而无法处理 --------------------------------------------------------------- 字符串的搜索替换可以用 preg_replace(),ereg_replace(),eregi_replace() 其中eregi_replace()在替换时不区分大小写 如果字符串中有特殊字符则可以使用转义 quotemeta preg_quote 如果是ereg函数组用quotemeta 如果是preg函数组用preg_quote 比如加粗文字 'din 1693(Pt.2)-1997' $str='din 1693(Pt.2)-1997'; echo preg_replace("/(".preg_quote($str).")/","<strong>//1</strong>",$str); //1就是引用找到的部份,这样可保留原来大小写. 如果用ereg或eregi的话,将preg_quote()改成quotemeta()就可以了 ./backdoor.php?page_name=body_index_1.htm&type=text&num=0 这样的perl的正则表达式放在//之间,其中的"?","."有问题, 所以有没有什么类似addslashes的函数能在这些符号前加上\,有吗?? 1 楼xuzuning(唠叨)回复于 2005-06-15 10:50:21 得分 25 quotemeta preg_quote 例 <?php $s = "./backdoor.php?page_name=body_index_1.htm&type=text&num=0"; echo quotemeta($s); ///./backdoor/.php/?page_name=body_index_1/.htm&type=text&num=0 echo preg_quote($s); //./backdoor/.php/?page_name/=body_index_1/.htm&type/=text&num/=0 echo preg_quote($s,"/"); ///.//backdoor/.php/?page_name/=body_index_1/.htm&type/=text&num/=0 ?>