php字符转码blog,php字符转码

[php]

/**

* 将非GBK字符集的编码转为GBK

*

* @param mixed $mixed 源数据

*

* @return mixed GBK格式数据

*/

function charsetToGBK($mixed)

{

if (is_array($mixed)) {

foreach ($mixed as $k => $v) {

if (is_array($v)) {

$mixed[$k] = charsetToGBK($v);

} else {

$encode = mb_detect_encoding()($v, array(‘ASCII’, ‘UTF-8’, ‘GB2312’, ‘GBK’, ‘BIG5’));

if ($encode == ‘UTF-8’) {

$mixed[$k] = iconv(‘UTF-8’, ‘GBK’, $v);

}

}

}

} else {

$encode = mb_detect_encoding($mixed, array(‘ASCII’, ‘UTF-8’, ‘GB2312’, ‘GBK’, ‘BIG5’));

//var_dump($encode);

if ($encode == ‘UTF-8’) {

$mixed = iconv(‘UTF-8’, ‘GBK’, $mixed);

}

}

return $mixed;

}

/**

* 将非UTF-8字符集的编码转为UTF-8

*

* @param mixed $mixed 源数据

*

* @return mixed utf-8格式数据

*/

function charsetToUTF8($mixed)

{

if (is_array($mixed)) {

foreach ($mixed as $k => $v) {

if (is_array($v)) {

$mixed[$k] = charsetToUTF8($v);

} else {

$encode = mb_detect_encoding($v, array(‘ASCII’, ‘UTF-8’, ‘GB2312’, ‘GBK’, ‘BIG5’));

if ($encode == ‘EUC-CN’) {

$mixed[$k] = iconv(‘GBK’, ‘UTF-8’, $v);

}

}

}

} else {

$encode = mb_detect_encoding($mixed, array(‘ASCII’, ‘UTF-8’, ‘GB2312’, ‘GBK’, ‘BIG5’));

if ($encode == ‘EUC-CN’) {

$mixed = iconv(‘GBK’, ‘UTF-8’, $mixed);

}

}

return $mixed;

}

[/php]

最后编辑:2015-05-11作者:sunny5156

0241ce914f3ca1e001b07a6287273dc5?s=96&d=retro&r=g

喜欢技术....

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值