如何 return 使用 PHP 在字符串中找到的特殊字符
How to return the special character found in string using PHP
我想使用 PHP 代码获取字符串中的特殊字符,这是我的试用代码:
$page_num =">256";
if(preg_match('^[-<>]+$', $page_num))
{
//Here it should returns special chars present in string..
}
你错过的是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);
检查这个
$page_num =">256";
if(preg_match_all('/\W/', $page_num,$matches))
{
print_r($matches);
}
我想使用 PHP 代码获取字符串中的特殊字符,这是我的试用代码:
$page_num =">256";
if(preg_match('^[-<>]+$', $page_num))
{
//Here it should returns special chars present in string..
}
你错过的是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);
检查这个
$page_num =">256";
if(preg_match_all('/\W/', $page_num,$matches))
{
print_r($matches);
}