php 如何检查特殊字符php
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3938021/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to check for special characters php
提问by stefanosn
Possible Duplicate:
preg_match php special characters
可能重复:
preg_match php 特殊字符
Hi all, I want to check if these characters exist in a string by using preg_match
:
大家好,我想使用以下命令检查字符串中是否存在这些字符preg_match
:
^'£$%^&*()}{@'#~?><>,@|\-=-_+-?'
^'£$%^&*()}{@'#~?><>,@|\-=-_+-?'
Help please!
请帮忙!
回答by chigley
<?php
$string = 'foo';
if (preg_match('/[\'^£$%&*()}{@#~?><>,|=_+?-]/', $string))
{
// one or more of the 'special characters' found in $string
}
回答by Petah
preg_match('/'.preg_quote('^\'£$%^&*()}{@#~?><,@|-=-_+-?', '/').'/', $string);
preg_match('/'.preg_quote('^\'£$%^&*()}{@#~?><,@|-=-_+-?', '/').'/', $string);