PHP mb_substr () function intercepts Chinese string application example, _php tutorial

Source: Internet
Author: User

The PHP mb_substr () function intercepts the Chinese string application example,


The substr () function is used to intercept strings, but there is a problem with Chinese characters, and mb_substr () and Mb_strcut functions can be similar to substr (), except that at the end of the function you add more than one parameter to set the encoding of the string. Using these two functions requires the Php_mbstring.dll to be opened in the php.ini.

<?php header ("content-type:text/html; Charset=utf-8 "); $string =" Hello, I'm good everyone "; Echo strlen ($string). '
'; Echo mb_substr ($string, 0,4, ' utf-8 '). ' ...
'; Echo mb_strcut ($string, 0,4, ' utf-8 '). ' ...';? >

Results of the output:

21st
Hello I'm good ...
You...

As can be seen from the above example, Mb_substr is to divide characters by word, while mb_strcut divides characters by bytes, but does not produce a half-character phenomenon.




http://www.bkjia.com/PHPjc/852375.html www.bkjia.com true http://www.bkjia.com/PHPjc/852375.html techarticle The php mb_substr () function intercepts the Chinese string application example, and the substr () function is used to intercept the string, but there is a problem for Chinese characters, and the Mb_substr () and mb_strcut are the two functions ...

  • 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.