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