The following error occurs when Chinese characters are output in php: $ load_list & nbsp; is a two-dimensional array. The user_name value is taken out of the first two characters and is replaced by an asterisk, however, garbled characters occur when encountering Chinese characters. it is useless to set the header () function. please find a solution. thank you! Foreach ($ load php output Chinese character garbled characters
The problem is as follows:
$ Load_list is a two-dimensional array. The user_name value in the array is taken out of the first two characters, which are replaced by asterisks. However, garbled characters occur when encountering Chinese characters. it is useless to set the header () function, please find a 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:
------ Solution --------------------
Your code only applies to single-byte strings, not considering
Chinese gbk, one character, two bytes
Chinese: UTF-8, one character, three bytes
------ Solution --------------------
Try the mb_substr function.
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.