ctype_punct to check punctuation character

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

ctype_punct() is a PHP filter function checks if only punctuation characters present in the $input_string ( nither letter, digit or blank space ). Any thing other than this if present then it returns FALSE.

Output is TRUE of all punctuation character(s) only present. ( neither letter, digit or blank space )
$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
ctype()

Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer