Open In App

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: 



Syntax: 

bool IntlChar::isWhitespace( $codepoint )

Parameters: This function accepts s single parameter $codepoint which is mandatory. 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:  




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

Output

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

Program 2: 




<?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));
}
?>

Output

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

Related Articles: 

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


Article Tags :