Php string extraction

Source: Internet
Author: User
: This article mainly introduces the extraction of php strings. if you are interested in the PHP Tutorial, you can refer to it. I. INTRODUCTION

Today we will introduce mb_substr () and mb_cutstr (). Php programming, whether it is web websites or platform development, uses string truncation in many cases. Before using php, modify the php. ini configuration file, open php_mbstring.dll, and remove the semicolon.

Php_mbstring.dll is a string encoding and string processing library. It is used to process unicode-based strings, such as UTF-8 and Chinese characters.

II. demonstration

1.

$ Str = 'nothing, that is why we fight! '; Echo mb_substr ($ str, 0,7, 'utf-8 ');

The output result is: nothing.

The mb_substr function has three parameters: the first is the string, the second is the starting and ending position of the truncation, and the third is the string encoding. it is very effective to intercept Chinese characters and prevent garbled characters. It is split by the number of words.

2.

$ Str = 'nothing, that is why we fight! '; Echo mb_strcut ($ str, 0,7, 'utf-8 ');

Output result: None

The mb_strcut function also has three parameters: character, start and end positions, and character encoding. Different from mb_substr, it is divided by the number of bytes. A word contains two bytes, but it does not contain half or half a byte. when the remaining one byte is used, no more words will be output.

III. Summary

Most of these two functions are used, and there is also a substr function, which is also used to extract strings, but it will encounter garbled characters when it is extracted, and is suitable for English. While mb_substr and mb_strcut are eaten by chinetouch. If you are interested, try this function on your own.

The above introduces the extraction of php strings, including the content, and hope to be helpful to friends who are interested in PHP tutorials.

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.