Home > Backend Development > PHP Tutorial > PHP string encoding conversion function can automatically identify the original encoding

PHP string encoding conversion function can automatically identify the original encoding

WBOY
Release: 2016-07-25 08:53:52
Original
730 people have browsed it
  1. /**
  2. * Data encoding conversion
  3. * @param array/string $data array
  4. * @param string $output converted encoding
  5. */
  6. function array_iconv($data,$output = 'utf-8') {
  7. $encode_arr = array('UTF-8','ASCII','GBK','GB2312','BIG5','JIS','eucjp-win','sjis-win','EUC-JP');
  8. $encoded = mb_detect_encoding($data, $encode_arr);//自动判断编码
  9. if (!is_array($data)) {
  10. return mb_convert_encoding($data, $output, $encoded);
  11. } // bbs.it-home.org
  12. else {
  13. foreach ($data as $key=>$val) {
  14. if(is_array($val)) {
  15. $data[$key] = array_iconv($val, $input, $output);
  16. } else {
  17. $data[$key] = mb_convert_encoding($data, $output, $encoded);
  18. }
  19. }
  20. return $data;
  21. }
  22. }
复制代码


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template