Mb_substr of PHP string sharding function

Source: Internet
Author: User
: This article mainly introduces the PHP string splitting function mb_substr. if you are interested in the PHP Tutorial, refer to it. PHP has many methods to process strings. tonight we have selected a very representative and widely used function explanation. it is a word.

String sharding function: mb_substr (). I hope you can learn it carefully!

// Mb_substr () has several parameters, usually three or four. in particular, the last parameter is encoded.

// In the following example, we will show how different codes are produced.

$ Str = 'We all have a dream rventrc ';
$ Str = mb_substr ($ str,); // because no encoding is specified, when one Chinese character is 3 characters long, it will output: 'me'
$ Str = mb_substr ($ str, 'utf8'); // because utf8 encoding is specified, a Chinese character must be 1 character in length, so the output will be:''
$ Str = mb_substr ($ str,-4th, 'utf8'); // This indicates that two characters are truncated starting from the last characters.
// It indicates that starting from subscript 2, it is intercepted until the last 5th characters (excluding the last 5th characters). Therefore, the result is: 'All have a dream RVs'

$ Str = mb_substr ($ str, 2,-5, 'utf8 ');

Through detailed analysis tonight, we believe we have a clearer understanding of intercepting Chinese strings. In fact, it is easy to set up encoding,

If you think the article is helpful to you, you can enjoy it at will!


The above introduces the PHP string sharding function mb_substr, including some content, hope to be helpful to friends who are interested in the PHP Tutorial.

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.