PHP string encoding conversion small example

WBOY
Release: 2016-07-25 08:53:47
Original
889 people have browsed it
  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. ?>
复制代码


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