ctype_print to printable characters including space

bool ctype_print ( string $input_string )
$input_string : String to be checked.

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

$str = array('string1' => "12$s", 'string2' => "Hello World", 'string3' => "asdf\n\r\t",'string4' => 43);
foreach ($str as $val => $string) {
if (ctype_print($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 consists 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 => 43 is not printable chars in above code ?

The function ctype_print() expects the input to be a string, hence 43 is considered as ASCII 43 ( which is equal to + ).

Difference between ctype_print() and ctype_graph()

$str="Hello World";
echo "output of ctype_print(): ".ctype_print($str);
echo "<br>";
echo "output of ctype_graph(): ".ctype_graph($str);
Output is here
output of ctype_print(): 1
output of ctype_graph():


Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com




    Post your comments , suggestion , error , requirements etc here .




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