Output Chinese characters garbled in PHP

Source: Internet
Author: User
foreach garbled

The problem is as follows:
$load _list is a two-dimensional array, the USER_NAME value is taken out of the first two characters, followed by asterisks instead, but encountered in Chinese characters garbled, set the header () function, also useless, to solve the solution, thank you!
foreach ($load _list as $k =>& $v) {
$temp =& $v [' user_name '];

For ($i =0, $len =strlen ($temp), $i < $len; $i + +) {
if ($i >1) {
$temp [$i]= ' * ';
}
}
}

As follows:


Reply to discussion (solution)

Your code only applies to single-byte strings, without considering
Chinese GBK A character of 2 bytes
Chinese Utf-8 A character of 3 bytes

Try the MB_SUBSTR function

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