Search code examples
phppreg-match

How to return the special character found in string using PHP


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..
 }

Solution

  • check this

    $page_num =">256";
     if(preg_match_all('/\W/', $page_num,$matches))
     {
           print_r($matches);
     }