Check for printable character(s) with ctype_print in PHP
Description
The following code shows how to check for printable character(s) with ctype_print.
Example
/*from w ww . j a v a 2 s . co m*/
<?php
$strings = array('string1' => "asdf\n\r\t", 'string2' => 'asf234r12', 'string3' => 'qweqwe#@%.54');
foreach ($strings as $name => $testcase) {
if (ctype_print($testcase)) {
echo "The string '$name' consists of all printable characters.\n";
} else {
echo "The string '$name' does not consist of all printable characters.\n";
}
}
?>
The code above generates the following result.