ctype_print() UTF-8 字符的最佳解决方案

Jor*_*ori 9 php utf-8 ctype

ctype_print()在 PHP 中,让(或者这是不可能的?)使用 UTF-8 的最佳方法是什么?目前,当我将它与某些 UTF-8 字符一起使用时,它会失败,例如:

\n\n
ctype_print("Cura\xc3\xa7ao");\n
Run Code Online (Sandbox Code Playgroud)\n\n

(在荷兰独立岛Cura\xc3\xa7ao之后)返回false

\n\n

预先感谢您的时间和帮助。

\n

cet*_*ver 0

这些ctype_print函数仅使用 ASCII 符号:

它是C isprint函数的包装

使用正则表达式

function ctype_print_utf(string $string): bool
{
    return preg_match('/[[:cntrl:]]/', $string) === 0;
}
Run Code Online (Sandbox Code Playgroud)