[Translation] use PHP to get the string length (strlen, mb_strlen)

Source: Internet
Author: User
Use PHP to get the string length (strlen, mb_strlen. Strlenintstrlen (stringstr) gets the length of the string specified as a parameter. Because the number of bytes is obtained, the halfwidth text is 1 byte and the fullwidth text is 2 bytes. Parameter: & nbsp; str object [Translation] use PHP to get the string length (strlen, mb_strlen)
Returns the length of a string.
strlenint strlen(string str)

Gets the length of the string specified as a parameter. Because the number of bytes is obtained, the halfwidth text is 1 byte and the fullwidth text is 2 bytes.

Parameters:
Str object string
Return value:
Number of bytes of a string

For the length of halfwidth text and fullwidth text, the following is an example:
strlen('abc') --> 3strlen('あいう') --> 6strlen('abcあいう') --> 9

If the number of bytes is not obtained, but the number of characters is obtained, use the [mb_strlen] function. But the halfwidth text is still full-width text,
All are processed in 1 text.
mb_strlenint mb_strlen(string str [, string encoding])

Parameters:
String object string
Character encoding of the encoding object string

Return value:
Number of characters in a string

The following is a practical test.
PHP TEST
 '); Print ($ str1. 'character number of characters'. $ str_character EN1. 'character counts

'); Print ($ str2.' maximum text column length limit comment '. $ str_len2.' maximum comment
'); Print ($ str2. 'maximum number of characters'. $ str_{en2. 'maximum number of characters

');?>

Publish the above file to the WEB server and access it via a browser. The result is as follows.


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.