from_encoding is specified by character code name before conversion. it can be array or string - comma separated enumerated list. If it is not specified, the internal encoding will be used.
/* Auto detect encoding from JIS, eucjp-win, sjis-win, then convert str to UCS-2LE */
$str = mb_convert_encoding($str, “UCS-2LE”, “JIS, eucjp-win, sjis-win”);
/* “auto” is expanded to “ASCII,JIS,UTF-8,EUC-JP,SJIS” */
$str = mb_convert_encoding($str, “EUC-JP”, “auto”);
例子:
$content = iconv(”GBK”, “UTF-8″, $content); $content = mb_convert_encoding($content, "UTF-8″,"GBK");
php中使用iconv函数时容易忽略的参数
今天在处理抓取内容的时候,当采用iconv进行编码转换的时候,发现结果会中断,猜是字符集的问题,考虑怎么跳过目标字符集不存在的字符,查手册发现iconv的函数只有三个参数,好像不行,然后查网上有人说可以,但是很奇怪怎么实现,最后发现英文描述有说可以加标识到目标编码后面:“TRANSLIT”,很郁闷怎么加呢?原来是先加“//”,真是郁闷,竟然有这样的设计
原型: $txtContent = iconv("utf-8",'GBK',$txtContent);
特殊参数:iconv("UTF-8","GB2312//IGNORE",$data)
两个可选的辅助参数:TRANSLIT和IGNORE ,(其中IGNORE 就是说遇到无法转换的就跳过)。