如何preg_match符号组合|〜|或%* |特定符号的PHP Preg_match
$harms = 'i.e. flow of electricity in contact with person(s)dsn fds fsdnfsnd fsd fmnds f|~|mnsdf <br /><br />ajshajkhsjkahs|~|';
if(preg_match('#\|~\|#', $harms)) {
echo 'true';
}
如何preg_match符号组合|〜|或%* |特定符号的PHP Preg_match
$harms = 'i.e. flow of electricity in contact with person(s)dsn fds fsdnfsnd fsd fmnds f|~|mnsdf <br /><br />ajshajkhsjkahs|~|';
if(preg_match('#\|~\|#', $harms)) {
echo 'true';
}
你一定要逃逸正则表达式特殊字符用反斜杠\
:
preg_match('#\|~\|#', $s);
preg_match('#%\*\|#', $s);
你也可以使用preg_quote()
转义特殊字符:
preg_match('#'.preg_quote('|~|%*|','#').'#', $s);
使用反斜线正则表达式元字符(在你的情况下是'|'和'*')。 – mario 2011-06-16 22:36:58
不适用于|〜| – hozza 2011-06-16 22:38:58
发布完整的'preg_match()'代码。 – mario 2011-06-16 22:40:35