如何返回使用PHP
问题描述:
我想用PHP代码来获得在字符串中的特殊字符在字符串中找到特殊字符,这是我的审判代码:如何返回使用PHP
$page_num =">256";
if(preg_match('^[-<>]+$', $page_num))
{
//Here it should returns special chars present in string..
}
答
检查这个
$page_num =">256";
if(preg_match_all('/\W/', $page_num,$matches))
{
print_r($matches);
}
答
你错过了什么是ending delimiter
$page_num =">256";
if(preg_match('^[-<>]+$^', $page_num))
^// this one
{
//Here it should returns special chars present in string..
}
演示你的代码,here
,或者你可以试试这个,
$string = 'your string here';
if (preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $string))
{
echo "yes";
} else {
echo "no";
}
还有一个解决办法是
preg_match('![^a-z0-9]!i', $string);
是 “特殊字符” 总是在第一位置发现了什么?其他字符是否始终为数字? –
不,它可能在字符串的任何地方像1-300, user3829086
你错过了结尾分隔符。请检查我的答案下面的更正和其他方法。 –