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

ctype_space() function in PHP


The ctype_space() function in PHP check for whitespace character(s). 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.

Syntax

ctype_space(str)

Parameters

  • str − The tested string

Return

The ctype_space() function 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

The following is an example −

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

Output

consists of all whitespace characters.
\test123 does not have all whitespace characters.

Example

<?php
$str = " ";
if (ctype_space($str))
echo "Whitespace!! \n";
else
echo "No Whitespace character! \n";
?>

Output

Whitespace!!