IntlChar::isprint() function in PHP

The IntlChar::isprint() function checks whether a given Unicode character is a printable character or not. A printable character is one that can be displayed and is not a control character.

Syntax

IntlChar::isprint( val )

Parameters

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

Return Value

The IntlChar::isprint() function returns TRUE if the character is printable, FALSE if not printable, or NULL on failure (invalid input).

Example 1: Testing Single Characters

The following example tests various single characters ?

<?php
    var_dump(IntlChar::isprint("K"));
    echo "<br>";
    var_dump(IntlChar::isprint("&"));
    echo "<br>";
    var_dump(IntlChar::isprint("<br>"));  // newline character
    echo "<br>";
    var_dump(IntlChar::isprint("5"));
?>
bool(true)
bool(true)
bool(false)
bool(true)

Example 2: Testing with Unicode Codepoints

You can also pass Unicode codepoint values directly ?

<?php
    var_dump(IntlChar::isprint(65));    // ASCII 'A'
    echo "<br>";
    var_dump(IntlChar::isprint(32));    // Space character
    echo "<br>";
    var_dump(IntlChar::isprint(9));     // Tab character
    echo "<br>";
    var_dump(IntlChar::isprint(128));   // Control character
?>
bool(true)
bool(true)
bool(false)
bool(false)

Key Points

  • The function only accepts single characters or their Unicode codepoint values

  • Multi-character strings return NULL

  • Control characters like newline, tab, and other non-printable characters return FALSE

  • Space character (ASCII 32) is considered printable

Conclusion

The IntlChar::isprint() function is useful for validating whether Unicode characters can be displayed. Remember to pass only single characters or codepoint values to avoid NULL returns.

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

190 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements