PHP | IntlChar::isWhitespace() Function

The IntlChar::isWhitespace() function is an inbuilt function in PHP which is used to check whether the given input character is a WhiteSpace character or not according to ICU. IntlChar access number utility function and used to access the information about Unicode Characters.

The White Space character is considered to ICU whitespace character if and only if it satisfies one of the following criteria:

  • It is a Unicode Separator character (categories “Z” = “Zs” or “Zl” or “Zp”) but is not also a non-breaking space (U+00A0 NBSP or U+2007 Figure Space or U+202F Narrow NBSP).
  • U+000A LINE FEED .
  • U+000B VERTICAL TABULATION.
  • U+000C FORM FEED.
  • U+000D CARRIAGE RETURN.
  • U+001C FILE SEPARATOR.
  • U+001D GROUP SEPARATOR.
  • U+001E RECORD SEPARATOR.
  • U+001F UNIT SEPARATOR.
  • U+0009 HORIZONTAL TABULATION.

Syntax:

bool IntlChar::isWhitespace( $codepoint )

Parameters: This function accepts single parameter $codepoint which is mandotary. The input parameter is a character or integer value, which is encoded as a UTF-8 string.

Return Value: If $codepoint is a whiteSpace character according to ICU then it returns True, otherwise return False.

Below programs illustrate the IntlChar::isWhitespace() Function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP code to illustrate 
// IntlChar::iswhitespace() function
  
//Input Capital Letter
var_dump(IntlChar::iswhitespace("R"));
echo "<br>";
  
//Input Small Letter
var_dump(IntlChar::iswhitespace(" r "));
echo "<br>";
  
//Input Whitesapce Character  "\n "
var_dump(IntlChar::iswhitespace("\n"));
echo "<br>";
  
//Input encoded string 
var_dump(IntlChar::iswhitespace("\u{00A0}"));
echo "<br>";
  
//Input Whitesapce  Space Character  
var_dump(IntlChar::iswhitespace(" "));
echo "<br>";
  
?>

chevron_right


Output:

bool(false)
NULL
bool(true)
bool(false)
bool(true)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP code to IntlChar::iswhitespace()
// function
  
// Declare an array $arr
$arr = array("\t", "\n", "^", "\r", "G\t");
  
// Loop run for every array element
foreach ($arr as $val){
      
    // Check each element as code point data
    var_dump(IntlChar::iswhitespace($val));
    echo "<br>";
}
?>

chevron_right


Output:

bool(true)
bool(true)
bool(false)
bool(true)
NULL

Related Articles:

References: http://php.net/manual/en/iswhitespace



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.