: This article describes how to obtain the length of a string in PHP. For more information about PHP tutorials, see. Use the strlen () function to obtain the string length.
Syntax:
Int strlen (string str)
Test:
$ Str = "123abc,.;"; echo strlen ($ str );
The result is as follows:
10
$ Str = "107 website Studio"; echo strlen ($ str );
The result is as follows:
18
At this time there will be questions, a total of 8 words, why the display length is 18, because in the case of UTF-8 encoding, three characters are a Chinese character, 3 + 5*3 = 18;
So the question is, can we display the number of characters in the string, such as the eight
In this case, a simple method is to extend php. ini, remove the semicolon before extension = php_mbstring.dll, and restart Apache.
$ Str = "107 website Studio"; echo mb_strlen ($ str, "UTF-8 ");
The running result is as follows:
8
Mixedmb_strlen (string$ Str[, String$ Encoding= Mb_internal_encoding ()])
EncodingThe parameter is character encoding. If omitted, internal character encoding is used.
The above describes how to obtain the length of a string in PHP, including the content, and hope to be helpful to friends who are interested in the PHP Tutorial.