This article analyzes the usage of strlen and Mb_strlen in PHP. Share to everyone for your reference, specific as follows:
First look at the following code (file encoding UTF8):
<?php
$utf 8_string = "ABCD I you he she it";
Var_dump (strlen ($utf 8_string));
Var_dump (Mb_strlen ($utf 8_string, ' gb2312 '));
Var_dump (Mb_strlen ($utf 8_string, ' UTF8 '));
Var_dump (Mb_strlen ($utf 8_string));
>
Run Result:
The 2nd parameter is the same as the original encoding of the string, and it calculates the real word in the human understanding sense. (only 1 times in Chinese text)
More interested in PHP related content readers can view the site topics: "PHP string (String) Usage summary", "PHP Array" Operation Techniques Encyclopedia, "PHP Basic Grammar Primer", "PHP Operations and Operator Usage Summary", " Introduction to PHP object-oriented programming program, "PHP Network Programming Skills Summary", "Php+mysql Database Operation Introduction" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design.