In php, the code (string, object, or array) is converted to each other cyclically. This article introduces how to use traversal to implement mutual conversion of String Encoding. for details about conversion of strings, objects, or arrays, see. The code is as follows. This article describes how to use traversal to implement mutual conversion of String Encoding. for details about how to convert strings, objects, or arrays, see.
| The code is as follows: |
|
|
/**
* Implement transcoding in a loop
*
* @ Param string $ param (string, object, or array), $ currCharset current encoding, $ toCharset expected encoding
* @ Return parameter type
*/
Function zhandi_iconv ($ param, $ currCharset, $ toCharset ){
If ($ currCharset! = $ ToCharset ){
If (is_string ($ param )){
Return iconv ($ currCharset, $ toCharset, $ param );
}
Elseif (is_array ($ param )){
Foreach ($ param as $ key => $ value ){
$ Param [$ key] = zhandi_iconv ($ value );
}
Return $ param;
}
Elseif (is_object ($ param )){
Foreach ($ param as $ key => $ value ){
$ Param-> $ key = zhandi_iconv ($ value );
}
Return $ param;
}
Else {
Return $ param;
}
}
Return $ param;
} |
Bytes. Copy the following code...