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

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP ctype_space() Function Usage and Example

PHP Ctype Function Manual

 The ctype_space() function checks if the characters in the provided string contain whitespace.

Syntax

ctype_space( $text );

Definition and Usage

 Check if the characters inside the provided string text contain whitespace.

Parameter

Serial NumberParameters and Description
1

text (required)

The string being tested.

Return value

If each character in text is ultimately output in some form of whitespace, return TRUE; otherwise, return FALSE. This includes whitespace characters, indentation, vertical tab, newline, carriage return, and formfeed characters.

Online Example

 Check if the characters inside the string elements of the array contain whitespace

<?php
   $strings = array('string1=> "\n\r\t", 'string2=> "\narf"12", 'string3=> '\n\r\t');
   
   foreach ($strings as $test) {
      if (ctype_space($test)) {
         echo "$test is composed of whitespace characters.\n";
      }else {
         echo "$test contains non-whitespace characters\n";
      }
   }
?>
Test to see‹/›

Output result:

	 Composed of whitespace characters.
arf12 Non-whitespace characters contained 
Non-whitespace characters contained

   PHP Ctype Function Manual