且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用php获取字符串的第一个字符包含特殊字符?

更新时间:2022-02-08 21:29:16

字符ü不是单字节字符.这是一个多字节(两个字节)的字符.

The character ü is not a single byte character. It is a multi-byte (two byte) character.

您正在尝试访问字符串的第一个字节,因此它不起作用.正是出于这个原因,已经设计了 mb_substr .

You are trying to access the first byte of the character string, so it doesn't work. Just for this very reason, mb_substr has been designed.

根据字符数执行多字节安全 substr()操作.位置从str的开头算起.第一个字符的位置为0.第二个字符的位置为1,依此类推.

Performs a multi-byte safe substr() operation based on number of characters. Position is counted from the beginning of str. First character's position is 0. Second character position is 1, and so on.

如果您只是尝试执行 $ name [0] ,则它是多字节字符的第一个字符,它只是一个空字符串或一个控制字符,用于显示 u 上方的code> .. .(以它为例,例如 .. + u = ü).

If you are just trying to do the $name[0], it get's the first character of the multi-byte character, which is just an empty string or a control character to display the .. above the u. (take it just for example, like .. + u = ü).