关于iconv容易忽略的参数IGNORE

 

      今天在提取抓取到的网页内容的正文时候,发现结果老是不完整,开始以为是提取不正确,然后去一步步分析提取结果,发现没问题,最后才发现是编码转换的环节的问题。我开始是直接使用iconv函数,

$txtContent = iconv("utf-8",'GBK',$txtContent);

utf-8直接转gbk,这样问题就来了,当有些字符无法转换的时候就从此处断开,导致内容不完整。后来又重新查手册,才发现iconv还有两个可选的辅助参数:TRANSLIT和IGNORE ,(其中IGNORE 就是说遇到无法转换的就跳过)。 其实也怪自己太粗心,刚开始一看iconv函数参数就三个,而且例子中也没有特别的,就懒得去看英文解释了,直接使用,直到出现了问题。

Description

string iconv ( string in_charset, string out_charset, string str )

Performs a character set conversion on the string str from in_charset to out_charset. Returns the converted string or FALSE on failure.

If you append the string //TRANSLIT to out_charset transliteration is activated. This means that when a character can't be represented in the target charset, it can be approximated through one or several similarly looking characters. If you append the string //IGNORE, characters that cannot be represented in the target charset are silently discarded. Otherwise, str is cut from the first illegal character.

 

 

原文链接:http://hi.baidu.com/yukinzhang/blog/item/82ad8e811baaf3debc3e1ede.html

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值