IntlChar::iscntrl() function in PHP

The IntlChar::iscntrl() function is used to check whether the given input is a control character or not. Control characters are special characters that don't have a visual representation, such as line feed (
), tab (\t), carriage return (\r), etc.

Syntax

IntlChar::iscntrl( val )

Parameters

  • val − An integer value or character encoded as a UTF-8 string.

Return Value

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

Example 1

The following example checks various characters for control character status −

<?php
    var_dump(IntlChar::iscntrl("<br>"));  // Line feed
    echo "<br>";
    var_dump(IntlChar::iscntrl("\t"));  // Tab character  
    echo "<br>";
    var_dump(IntlChar::iscntrl("A"));   // Regular letter
    echo "<br>";
    var_dump(IntlChar::iscntrl("123")); // String of digits
?>
bool(true)
bool(true)
bool(false)
NULL

Example 2

Here's another example checking different control characters −

<?php
    var_dump(IntlChar::iscntrl("\r"));    // Carriage return
    echo "<br>";
    var_dump(IntlChar::iscntrl(chr(7)));  // Bell character
    echo "<br>";
    var_dump(IntlChar::iscntrl(" "));     // Space character
?>
bool(true)
bool(true)
bool(false)

Conclusion

The IntlChar::iscntrl() function is useful for identifying control characters in text processing. It returns TRUE for control characters like
, \t, \r and FALSE for visible characters.

Updated on: 2026-03-15T07:43:53+05:30

182 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements