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$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

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.