Examples of string length functions commonly used in PHP strlen () and Mb_strlen () are explained

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.