class_Chareset.php

2024-07-05 19:58 更新
<?php /* * @copyright Leyun internet Technology(Shanghai)Co.,Ltd * @license http://www.dzzoffice.com/licenses/license.txt * @package DzzOffice * @link http://www.dzzoffice.com * @author qchlian(3580164@qq.com) */ class Chareset{ // 自動轉換字符集 支持數(shù)組轉換 public function autocharset($string, $from='gbk', $to='utf-8') { $from = strtoupper($from) == 'UTF8' ? 'utf-8' : $from; $to = strtoupper($to) == 'UTF8' ? 'utf-8' : $to; if (strtoupper($from) === strtoupper($to) || empty($string) || (is_scalar($string) && !is_string($string))) { //如果編碼相同或者非字符串標量則不轉換 return $string; } if (is_string($string)) { if (function_exists('mb_convert_encoding')) { return mb_convert_encoding($string, $to, $from); } elseif (function_exists('iconv')) { return iconv($from, $to, $string); } else { return $string; } } elseif (is_array($string)) { foreach ($string as $key => $val) { $_key = self::autocharset($key, $from, $to); $string[$_key] = self::autocharset($val, $from, $to); if ($key != $_key) unset($string[$key]); } return $string; } else { return $string; } } } ?>


以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號