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$str 1= "ABCdef";//Output 6 $str 2= "AB CD";//Output 7, note, opening, ending, middle space $STR 3= "Hello China";//output 12, but varies, related to the character encoding used by the system $STR 4= "Hello, China";//output 15, but varies, related to the character encoding used by the system Echo' $STR 1 byte length is: '.strlen($str 1).‘ The byte length of $str 2 is: '.strlen($str 2).‘‘; Echo' $str 3 byte length 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 a string with the encoding encoding str contains the [number of characters], multibyte characters are counted as 1
<?PHP$str 1= "ABCdef";//Output 6 $str 2= "AB CD";//Output 7 Note that the opening, closing, and middle spaces $STR 3= "Hello China";//Output 4 $STR 4= "Hello, China";//Output 5 EchoThe character length of ' $str 1 is: '. Mb_strlen ($str 1, "Utf-8"). ' The character length of $str 2 is: '. Mb_strlen ($str 2, "Utf-8"). "; EchoThe character length of ' $str 3 is: '. Mb_strlen ($STR 3, "Utf-8"). ' The character length of $str 4 is: '. Mb_strlen ($STR 4, "Utf-8"). ";?>
Examples of string length functions commonly used in PHP strlen () and Mb_strlen () are explained