我想用PHP代碼來獲得在字符串中的特殊字符在字符串中找到特殊字符,這是我的審判代碼:如何返回使用PHP
$page_num =">256";
if(preg_match('^[-<>]+$', $page_num))
{
//Here it should returns special chars present in string..
}
我想用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,<200 – user3829086
你錯過了結尾分隔符。請檢查我的答案下面的更正和其他方法。 –