ctype_graph to printable characters except space

$var='Hi Welcome'; // All are printable character(s) except space
//$var='plus2net'; //  All are printable character(s) except space
//$var='Hi \n welcome'; // All or some are NOT printable character(s)
//$var='abcd \t xy'; // All or some are NOT printable character(s)

if(ctype_graph($var)){
	echo "$var All are printable character(s) except space ";
}else{ 
	echo " $var All or some are NOT printable character(s)";
}
Syntax
bool ctype_graph ( string $input_string )
$input_string : String to be checked.

ctype_graph() is a PHP filter function checks if all chars in the $input_string are printable characters except space or not. Any thing other than this if present then it return FALSE.

$str = array('string1' => "12$s", 'string2' => "Hello World", 'string3' => "asdf\n\r\t",'string4' => 32);
foreach ($str as $val => $string) {
if (ctype_graph($string)) {
 echo "<p class='text-success'>The string <b>$val</b> consists of all  printable character(s)</p><br>";
}else {
 echo "<p class='text-danger'>The string <b>$val</b> does not consist of all printable character(s)</p><br>";
 }
}
Output is here

The string string1 consists of all printable character(s)


The string string2 does not consist of all printable character(s)


The string string3 does not consist of all printable character(s)


The string string4 does not consist of all printable character(s)

Why the $string4 => 32 is not printable chars in above code ?

The function ctype_graph() expects the input to be a string, hence 32 is considered as ASCII 32 ( which is equal to space ).
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