Computer >> Computer tutorials >  >> Programming >> PHP

ctype_print() function in PHP


The ctype_print() check for printable character(s). It returns TRUE if every character in text will actually create output (including blanks). Returns FALSE if text contains control characters or characters that do not have any output or control function at all.

Syntax

ctype_print(sr)

Parameters

  • str − The tested string

Return

The ctype_print() function returns TRUE if every character in text will actually create output (including blanks). Returns FALSE if text contains control characters or characters that do not have any output or control function at all.

Example

The following is an example −

<?php
$arr = array('asdf\n\r\t', 'yu67', "fooo#int%@");
foreach ($arr as $x) {
   if (ctype_print($x)) {
      echo "$x has all printable characters. \n";
   } else {
      echo "$x does not have all printable characters. \n";
   }
}
?>

Output

asdf\n\r\t has all printable characters.
yu67 consists of all printable characters.
fooo#int%@ consists of all printable characters.