我在这里和谷歌搜索 也许我没有合适的关键词。
我错了什么?
$str="Hello \ ' \" World."; echo $str;
if (preg_match('/\\\'\"/',$str)) echo "<br>String has \ and \" and ' !";
编辑(解决方案):
$str="Hello \ ' \" World."; echo $str;
if (preg_match( '/[*"]|[*\']|[*\\\]/',$str)) echo "<br>String has \ and \" and ' !";
答案 0 :(得分:1)
'
和"
之间有空格。使用此正则表达式使其工作:
php> if (preg_match('/\\\' *"/',$str)) echo "<br>String has \ and \" and ' !";
<br>String has \ and " and ' !
使用此正则表达式:
/\\\' *"/
^^
|------------ Using " *" to allow 0 or more spaces here
答案 1 :(得分:1)
试试这个: /[\\\\'\"]+/
$re = "/[\\\\'\"]+/";
$str = "Hello \ ' \" World.";
preg_match_all($re, $str, $matches);