PHP - Function ctype_space()


Advertisements


Syntax

ctype_space ( $text );

Definition and Usage

This function checks if all of the characters in the provided string, text, creates whitespace.

Parameters

Sr.No Parameter & Description
1

text(Required)

The tested string.

Return Value

It returns TRUE if every character in text creates some sort of white space, FALSE otherwise. Besides the blank character this also includes tab, vertical tab, line feed, carriage return and form feed characters.

Example

Try out following example −

Live Demo
<?php
   $strings = array('\n\r\t', '\test123' );
   
   foreach ($strings as $test) {
      if (ctype_space($test)) {
         echo "$test consists of all whitespace characters. \n";
      }else {
         echo "$test does not have all whitespace characters. \n";
      }
   }
?> 

This will produce the following result −

\n\r\t does not have all whitespace characters.
\test123 does not have all whitespace characters.

php_function_reference.htm

Advertisements