PHP strlen definition of Chinese

$ ZhStr = 'Hello, China! ';

 

// Each Chinese character bytes occupied by the encoded gbk 2
echo strlen ($ zhStr); // Output: 12

// utf-8 character encoding in each Chinese occupied bytes 3

echo strlen ($ zhStr); // Output: 18

 

Therefore, the determination to make the string or the length of time taken to note: length should be an integer multiple of 2 or a multiple of 3.

Otherwise, the error will be:

Malformed UTF-8 characters, possibly incorrectly encoded

Malformed UTF-8 character encoding may not be correct

 

Guess you like

Origin www.cnblogs.com/xiaonanmu/p/11226787.html