PHP iconv_strlen()意思是问题

HEL*_*ELP 8 php iconv

我想知道下面的句子对我们的假人来说简单来说意味着什么?

什么是字节序列?一个字节中有多少个字符?

iconv_strlen() counts the occurrences of characters in the given byte sequence str on the basis of the specified character set, the result of which is not necessarily identical to the length of the string in byte.

ont*_*ia_ 12

让我们以日语字符'こ'为例.假设UTF-8编码,这是一个3字节字符(0xE3 0x81 0x93).让我们看看当我们使用时会发生什么strlen:

$ php -r 'echo strlen("?") . "\n";'
3
Run Code Online (Sandbox Code Playgroud)

结果是3,因为strlen计算字节.但是,根据UTF-8编码,这只是一个字符.这就是它的位置iconv_strlen.它知道在UTF-8中,这是一个单个字符,即使它由3个字节组成.所以,如果我们尝试这样做:

$ php -r 'echo iconv_strlen("?", "UTF-8") . "\n";'
1
Run Code Online (Sandbox Code Playgroud)

我们得到1.这就是那个解释意味着要指出的.