PHP truncation function mb_substr () _ PHP Tutorial

Source: Internet
Author: User
PHP truncation function mb_substr. In php, the mb_substr () function is a function used to intercept Chinese characters and English letters. it can be used to quickly intercept the length of specified characters. I will introduce it to you. Tip: In php, the mb_substr () function is used to intercept Chinese and English characters. it can be used to quickly and conveniently intercept the length of specified characters. I will introduce it to you.

Tip: mb_substr is not supported by default in php. we need to find php in the windows directory. ini open edit and search for mbstring. dll, find; extension = php_mbstring.dll and remove the previous; number to use the mb_substr function.

Function: mb_substr ($ str, $ start, $ length, $ encoding)

$ Str: string to be truncated
$ Start: truncation start
$ Length, length (note: This is different from mb_strimwidth. 1 represents a Chinese character)
$ Encoding, encoding, I set it to UTF-8

For example, the title of an article is truncated and 15 characters are allowed.

The code is as follows:


$ Str = 'so that my string will not contain garbled characters ^_^ ';

Echo "mb_substr:". mb_substr ($ str, 0, 7, 'utf-8 ');
// Result:
Echo"
";

Echo "mb_strcut:". mb_strcut ($ str, 0, 6, 'utf-8 ');
// Result:
?>

In summary, he can intercept Chinese characters.


The extract () function is a function used to intercept Chinese and English characters. it can be used to quickly intercept specified characters. I will introduce it to you. Tip: mb_subs...

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.