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

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP ctype_graph() Function Usage and Example

PHP Ctype Function Manual

The ctype_graph() function performs printable string detection, excluding spaces

Syntax

ctype_graph(\$text);

Definition and Usage

 Check if the characters output inside the provided text are all visible.

Parameter

Serial NumberParameters and Description
1

text (required)

String to be tested

Return Value

If each character in the text is printable and actually creates visible output (without spaces), it returns TRUE; otherwise, it returns FALSE.

Online Example

<?php
   \$strings = array('string1' => "asdf\n\r\t", 'string2' => 'arf12', 'string3' => 'LKA#@%.54');   
   foreach (\$strings as \$test) {
      if (ctype_graph(\$test)) {
         echo "\$test consists of visible and printable characters\n";
      }else {
         echo "\$test contains invisible characters.\n";
      }
   }
?>
Test and see‹/›

Output result:

asdf
	 Contains invisible characters. 
arf12 Consisting of visible and printable characters 
LKA#@%.54 Consisting of visible and printable characters

   PHP Ctype Function Manual