Extraction of PHP strings

Source: Internet
Author: User
First, introduce

Today is the introduction of MB_SUBSTR () and Mb_cutstr (). PHP programming, whether it is a Web site, or platform development, a lot of time to use the interception of strings. Before use, to modify the php.ini configuration file, the Php_mbstring.dll open, remove the front;

Php_mbstring.dll is a library of string encoding and string processing. is to handle Unicode-encoded strings, such as utf-8, Kanji, and so on.

Two, demo

1.

$str = ' Nothing is a reason to spell! '; Echo mb_substr ($str, 0,7, ' utf-8 ');

The output is: nothing, just

Mb_substr function has three parameters, the first is a string, the second is the location of the start and end of The Intercept, the third is the encoding of the string, interception of Chinese is very effective, to prevent garbled. It is segmented by the number of words.

2.

$str = ' Nothing is a reason to spell! '; Echo mb_strcut ($str, 0,7, ' utf-8 ');

The output is: no

Mb_strcut The function is also a three parameter, character, start and end position, character encoding. unlike mb_substr , it is divided by the number of bytes. A word of two bytes, and it does not appear half a word or half a byte of the case, when the remaining one byte will no longer output a word.

Three, Summary

most use these two functions, there is also a substr function, this function is also used to extract the string, but it is extracted when encountered in Chinese will be garbled error, suitable for use in English. and mb_substr and mb_strcut are both Chinese and English. You can also try this function on your own.

The above describes the PHP string extraction, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

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