Reputation: 363
I want to get the special chars found in string using PHP code, Here is my trial code:
$page_num =">256";
if(preg_match('^[-<>]+$', $page_num))
{
//Here it should returns special chars present in string..
}
Upvotes: 0
Views: 51
Reputation: 1835
check this
$page_num =">256";
if(preg_match_all('/\W/', $page_num,$matches))
{
print_r($matches);
}
Upvotes: 2
Reputation: 11987
What you have missed is ending delimiter
$page_num =">256";
if(preg_match('^[-<>]+$^', $page_num))
^// this one
{
//Here it should returns special chars present in string..
}
Demo of your code, here
or you can try this,
$string = 'your string here';
if (preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $string))
{
echo "yes";
} else {
echo "no";
}
One more solution is
preg_match('![^a-z0-9]!i', $string);
Upvotes: 1