English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP ctype_print() Function Usage and Example

PHP Ctype Function Manual

The ctype_print() function performs printable character detection, checking if all characters in the string are printable characters.

Syntax

ctype_print( $text );

Definition and Usage

This function checks if all characters in the provided string are printable.

Parameter

Serial NumberParameters and Description
1

text (required)

The string being tested.

Return value

If all characters in the text can be actually output in the current language environment (including whitespace), it returns TRUE; if the text contains control characters or strings that will not output anything, it returns FALSE.

Online Example

Check if all characters in the text are printable characters, note that the output of single quotes and double quotes in the following example is different

<?php
   $strings = array('asdf\n\r\t', "asdf\n\r\t", 'k211', "fooo#int%@")
   
   foreach ($strings as $test) {
      if (ctype_print($test)) {
         echo "$test All are printable characters \n";
      }else {
         echo "$test Contains non-printable characters \n";
      }
   }
?>
Test and see‹/›

Output result:

asdf\n\r\t All are printable characters 
asdf
	 Contains non-printable characters 
k211 All are printable characters 
fooo#int%@ All are printable characters

   PHP Ctype Function Manual