How to use ctype_punct() function to check if all characters in a string are printable punctuation in PHP

1 Answer

0 votes
$arr = array('13.5\n', 'abcXYZ', 'AbCd1fgH7', 'xyz@!$wsp', '*$!()[]');
     
foreach ($arr as $s) 
{
    if (ctype_punct($s)) 
        echo "$s is all punctuation <br />";
    else
        echo "$s is NOT all punctuation <br />";
}
     
/*
run:
   
13.5\n is NOT all punctuation
abcXYZ is NOT all punctuation
AbCd1fgH7 is NOT all punctuation
xyz@!$wsp is NOT all punctuation
*$!()[] is all punctuation 
      
*/

 



answered Mar 18, 2016 by avibootz
...