php 其他字符转utf-8

function convertToUtf8($value, $sourceEncoding)
{
    if(is_string($value))
        $value = mb_convert_encoding($value,'UTF-8',$sourceEncoding);
    else if (is_array($value))
    {
        foreach($value as &$element)
            convertToUtf8($element, $sourceEncoding);
    }
     return $value;
}

$arr = array('你好世界');

$a = convertToUtf8($arr,'gbk');
var_dump($a);

2 条评论

发表评论

*