How to use ctype_punct() to checks if all of the characters in a string are punctuation characters in PHP

1 Answer

0 votes
$str = array('abc#,!', '!$, #', '*,!&$.');
foreach ($str as $s) 
{
    if (ctype_punct($s)) 
        echo "string: $s - include only punctuation characters <br />";
    else 
        echo "string: $s - NOT include only punctuation characters <br />";
}


/*
run: 

string: abc#,! - NOT include only punctuation characters
string: !$, # - NOT include only punctuation characters
string: *,!&$. - include only punctuation characters 

*/

 



answered Jun 6, 2016 by avibootz
...