$var="$)@*"; // All are punctuation character(s)
//$var="^#(b!"; // All or some are NOT punctuation character(s)
if(ctype_punct($var)){
echo "<b>$var</b> All are punctuation character(s)";
}else{
echo " <b>$var</b> All or some are NOT punctuation character(s)";
}
Output
$)@* All are punctuation character(s)
Syntax
bool ctype_punct ( string $input_string )
$input_string : String to be checked. $input_string ( nither letter, digit or blank space ). Any thing other than this if present then it returns FALSE.
$str = array("#$)s", "$@!&)(", "2*;^@",38);
foreach ($str as $val) {
if (ctype_punct($val)) {
echo "<p class='text-success'>The string <b>$val</b> consists of all punctuation character(s).</p>";
} else {
echo "<p class='text-danger'>The string <b>$val</b> does not consist of all punctuation character(s)</p>";
}
}
Output is here
The string #$)s does not consist of all punctuation character(s)
The string $@!&)( consists of all punctuation character(s).
The string 2*;^@ does not consist of all punctuation character(s)
The string 38 consists of all punctuation character(s).
Check for only alphabetic characters by ctype_alpha()
Check for all lower or upper
Check for at least one lower case or upper case
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.