PHP mb_substr function intercept Chinese characters related issues

Source: Internet
Author: User
PHP mb_substr function intercept Chinese characters problem
Use the PHP mb_substr function to intercept the first 2 and the last 2 characters of a variable, the content of the variable is Chinese characters, but only the first 2 characters can not be output after 2 characters, is not the MB_SUBSTR function is not supported from the tail intercept? Also please expert guidance.
$IP = "Foshan Telecommunications in Guangdong province";
Echo mb_substr ($ip, 0,2, ' utf-8 ');
Echo mb_substr ($ip, -2, ' utf-8 ');
?>

Current output: Guangdong
Hope output: Guangdong Telecom


Thank you!

Share to:


------Solution--------------------
Mb_internal_encoding ("UTF-8");
$IP = "Foshan Telecommunications in Guangdong province";
Echo mb_substr ($ip, 0,2);
Echo Mb_substr ($ip,-2);

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