The role and Difference of Php--strlen () and Mb_strlen

Source: Internet
Author: User
In PHP, strlen and Mb_strlen is a function of string length PHP built-in string length function strlen Unable to correctly handle the Chinese string, it gets only the number of bytes of the string. For the Chinese encoding of GB2312, the value of strlen is twice times the number of Chinese characters, and for UTF-8 encoded Chinese, is 3 times times (in UTF-8 encoding, a Chinese character accounted for 3 bytes). Using Mb_strlen function can solve this problem well. The usage of Mb_strlen is similar to strlen, except that it has a second optional parameter for specifying character encoding. For example get UTF-8 string str length, can be used with Mbstrlen (str length, can be used with Mbstrlen (str, ' UTF-8 '). If you omit the second argument, the internal encoding of PHP is used. The internal code can be obtained through the mb_internal_encoding () function. It is important to note that Mb_strlen is not a PHP core function and needs to be sure that the Php_mbstring.dll is loaded in the php.ini before use, that is, to ensure that the "Extension=php_mbstring.dll" line is present and not commented out. Otherwise, there is an issue with undefined functions.

The role and Difference of Php--strlen () and Mb_strlen

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.