int strlen (String $string)
int strlen (string $string) Gets the length of the string $string if the [byte] length of the given string succeeds, and returns 0 if $string is empty.
<?PHP$STR1 = "abcdef";//output 6$STR2 = "AB CD";//Output 7, note that the opening, the end, the middle of the space $str3 = "Hello China";//output 12, but will change, and the system used by the character encoding method $STR4 = "China , hello ";//Output 15, but will vary, and the system uses the character encoding method for Echo ' $STR 1 byte length: '. strlen ($str 1). ' The byte length of $str 2 is: '. strlen ($str 2). "; The byte length of Echo ' $str 3 is: '. strlen ($str 3). ' The byte length of $str 4 is: '. strlen ($str 4). "; ?>
Mb_strlen ()-Gets the length of the string
mixed Mb_strlen (String $str [, String $encoding = Mb_internal_encoding ()])
$str to check the length of the string
$encoding, character encoding can be specified, such as ellipsis using internal character encoding
return Value: Returns the string with the encoding encoding str contains[number of characters], multibyte characters are counted as 1
<?PHP$STR1 = "abcdef";//output 6$STR2 = "AB CD";//Output 7 Note that the start, end, and middle spaces $str3 = "Hello China";//Output 4$STR4 = "China, hello";//Output 5echo ' $STR 1 characters The length is: '. Mb_strlen ($str 1, "Utf-8"). ' The character length of $str 2 is: '. Mb_strlen ($str 2, "Utf-8"). "; The character length of Echo ' $str 3 is: '. Mb_strlen ($str 3, "Utf-8"). ' The character length of $str 4 is: '. Mb_strlen ($str 4, "Utf-8"). "; >
This article is from the "Golden Three" blog, please be sure to keep this source http://jinsanguo.blog.51cto.com/13363984/1970257
Examples of string length functions commonly used in PHP strlen () and Mb_strlen () are explained