IntlChar::isWhitespace() function in PHP

The IntlChar::isWhitespace() function checks whether the given input character is a whitespace character or not. This function is part of PHP's Intl extension and follows Unicode standards for whitespace detection.

Syntax

IntlChar::isWhitespace(val)

Parameters

  • val − A character or integer value encoded as a UTF-8 string, or a Unicode code point.

Return Value

The IntlChar::isWhitespace() function returns TRUE if the character is a whitespace character, FALSE otherwise, or NULL on failure.

Example

The following example demonstrates how to use IntlChar::isWhitespace() with different characters ?

<?php
   var_dump(IntlChar::isWhitespace("M"));
   echo "<br>";
   var_dump(IntlChar::isWhitespace(" "));
   echo "<br>";
   var_dump(IntlChar::isWhitespace("\t"));
   echo "<br>";
   var_dump(IntlChar::isWhitespace("<br>"));
   echo "<br>";
   var_dump(IntlChar::isWhitespace("&"));
?>
bool(false)
bool(true)
bool(true)
bool(true)
bool(false)

Unicode Code Points

You can also pass Unicode code points directly ?

<?php
   // Space character (U+0020)
   var_dump(IntlChar::isWhitespace(0x0020));
   echo "<br>";
   // Tab character (U+0009) 
   var_dump(IntlChar::isWhitespace(0x0009));
   echo "<br>";
   // Letter A (U+0041)
   var_dump(IntlChar::isWhitespace(0x0041));
?>
bool(true)
bool(true)
bool(false)

Conclusion

IntlChar::isWhitespace() is useful for Unicode-aware text processing, detecting various types of whitespace characters including spaces, tabs, and line breaks according to Unicode standards.

Updated on: 2026-03-15T07:46:19+05:30

101 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements