How to garbled characters after setting character sets

Source: Internet
Author: User
How can we garbled $ load_list & nbsp; after setting the character set? $ load_list & nbsp; is a two-dimensional array. The user_name value is taken out of the first two characters and replaced by an asterisk. However, garbled characters still exist after setting the character set, however, the first two characters must be displayed in Chinese. the asterisks are used to represent foreach ($ load_list & nbsp; as & nbsp; $ k = & gt; how can I garbled characters after setting the character set?
$ Load_list is a two-dimensional array, in which the user_name value is taken out of the first two characters, followed by asterisks, but garbled characters still exist after the character set, but the first two characters must be displayed in Chinese, it is represented by an asterisk.
Foreach ($ load_list as $ k =>&$ v ){

$ Temp = & $ v ['User _ name'];
// Determine whether there is any Chinese character
If (! Preg_match ('/^ ([\ x81-\ xfe] [\ x40-\ xfe]) {0, 2} $/', $ temp )){
$ Len = mb_strlen ($ temp, 'utf-8 ');
} Else {
$ Len = strlen ($ temp );
}
For ($ k = 0; $ k <$ len; $ k ++ ){
If ($ k> 1 ){
$ Temp [$ k] = '*';
}
After setting the character set, garbled characters are also shared:
------ Solution --------------------
$ Temp = 'Judge whether there is any Chinese ';
// Determine whether there is any Chinese character
If (preg_match ('/[\ x81-\ xfe] [\ x40-\ xfe]/', $ temp )){
Mb_internal_encoding ("gbk ");
} Else {
Mb_internal_encoding ("UTF-8 ");
}
$ Len = mb_strlen ($ temp );
$ T = '';
For ($ k = 0; $ k <$ len; $ k ++ ){
If ($ k> 1 ){
$ T. = '*';
} Else {
$ T. = mb_substr ($ temp, $ k, 1 );
}
}
Echo $ t;
Judgement *****

------ Solution --------------------
Echo base64_encode ($ v ['User _ name']);
Paste the result!

If you don't give a question, how can you know why?
------ Solution --------------------
You have made a mistake on your own. you can't blame the algorithm!
$ T = & $ v ['User _ name'];
It should be $ v ['User _ name'] = $ t;
$ Load_list = array (
Array ('User _ name' => 'xiaodg '),
Array ('User _ name' => 'xforwarded66 '),
Array ('User _ name' => 'etea '),
Array ('User _ name' => 'na0617 '),
Array ('User _ name' => 'kimo '),
Array ('User _ name' => 'shadow '),
Array ('User _ name' => 'vian22 '),
Array ('User _ name' => 'qingyu '),
Array ('User _ name' => 'jiangliman '),
Array ('User _ name' => 'xiaobu '),
Array ('User _ name' => 'xiaobu '),
Array ('User _ name' => 'hfa818 '),
);

Foreach ($ load_list as $ k =>&$ v ){
$ Temp = $ v ['User _ name'];

// Determine whether there is any Chinese character
If (preg_match ('/[\ x81-\ xfe] [\ x40-\ xfe]/', $ temp )){
Mb_internal_encoding ("gbk ");
} Else {
Mb_internal_encoding ("UTF-8 ");
}
$ Len = mb_strlen ($ temp );
$ T = '';
For ($ k = 0; $ k <$ len; $ k ++ ){
If ($ k> 2 ){
$ T. = '*';
} Else {
$ T. = mb_substr ($ temp, $ k, 1 );
}
}
$ V ['User _ name'] = $ t;
}
Print_r ($ load_list );
Array
(
[0] => Array
(
[User_name] => xia ***
)

[1] => Array
(
[User_name] => x42 ***
)

[2] => Array
(
[User_name] => ete *
)

[3] => Array
(
[User_name] => na0 ***
)

[4] => Array
(
[User_name] => kim *
)

[5] => Array
(
[User_name] => shadow
)

[6] => Array
(
[User_name] => ***
)

[7] => Array
(
[User_name] => qin ***
)

[8] => Array
Related Article

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.