PHP development skills (10)-implementation of Chinese character string truncation without garbled characters

Source: Internet
Author: User
During development, we often intercept strings as needed. if it is a string of English strings, it will not be garbled; but if it is a Chinese string, in many cases, garbled characters may occur due to the length of the truncated part. The following describes how to intercept Chinese strings without garbled characters: during development, we often intercept strings as needed. if it is a string of English strings, we will not see garbled characters during interception. However, if it is a Chinese string, garbled characters may often occur based on the length of the interception. The following describes how to intercept Chinese strings without garbled characters:

 $ Length) {$ str = mb_substr ($ string, $ start, $ length, 'utf-8'); return $ str. '... ';}else {return $ string ;}}?>

Related articles:

A small function that inserts a string at a specified position.

Php custom truncation of Chinese Strings-utf8

Code explanation of string format calculation formula using eval in php

The above is the PHP development technique (10)-detailed content of the implementation method of Chinese character string truncation without garbled characters. For more information, please refer to other related articles in the first PHP community!

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.