Home  >  Article  >  Backend Development  >  PHP string encoding conversion small example

PHP string encoding conversion small example

WBOY
WBOYOriginal
2016-07-25 08:53:47849browse
  1. function phpcharset($data, $to) {
  2. if(is_array($data)) {
  3. foreach($data as $key => $val) {
  4. $data[$key] = phpcharset($val, $to);
  5. }
  6. } else {
  7. $encode_array = array('ascii', 'utf-8', 'gbk', 'gb2312', 'big5');
  8. $encoded = mb_detect_encoding($data, $encode_array);
  9. $to = strtoupper($to);
  10. if($encoded != $to) {
  11. $data = mb_convert_encoding($data, $to, $encoded);
  12. }
  13. }
  14. return $data;
  15. }
  16. ?>
复制代码


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn