首頁  >  文章  >  後端開發  >  php字符串编码转换小例子

php字符串编码转换小例子

WBOY
WBOY原創
2016-07-25 08:53:47845瀏覽
  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. ?>
复制代码


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn