|
這幾天有在用simple_html_dom抓一些文章。不同網站的編碼在國內基本上是gbk gb2312 utf-8。而以gb2312和utf-8居多。
我這一版的simple_html_dom有一個方法 convert_text 是這個樣子的。
復制代碼 代碼如下:
// PaperG - Function to convert the text from one character set to another if the two sets are not the same.
function convert_text($text)
{
global $debug_object;
if (is_object($debug_object)) {$debug_object->debug_log_entry(1);}
$converted_text = $text;
$sourceCharset = "";
$targetCharset = "";
if ($this->dom)
{
$sourceCharset = strtoupper($this->dom->_charset);
$targetCharset = strtoupper($this->dom->_target_charset);
}
if (is_object($debug_object)) {$debug_object->debug_log(3, "source charset: " . $sourceCharset . " target charaset: " . $targetCharset);}
if (!empty($sourceCharset) && !empty($targetCharset) && (strcasecmp($sourceCharset, $targetCharset) != 0))
{
// Check if the reported encoding could have been incorrect and the text is actually already UTF-8
if ((strcasecmp($targetCharset, 'UTF-8') == 0) && ($this->is_utf8($text)))
{
$converted_text = $text;
}
else
{
$converted_text = iconv($sourceCharset, $targetCharset, $text);
}
}
// Lets make sure that we don't have that silly BOM issue with any of the utf-8 text we output.
if ($targetCharset == 'UTF-8')
{
if (substr($converted_text, 0, 3) == "/xef/xbb/xbf")
{
$converted_text = substr($converted_text, 3);
}
if (substr($converted_text, -3) == "/xef/xbb/xbf")
{
$converted_text = substr($converted_text, 0, -3);
}
}
return $converted_text;
}
來看這一行:
復制代碼 代碼如下:
$converted_text = iconv($sourceCharset, $targetCharset, $text);
會引起轉碼不正確。比如會把gb2312的文字轉成:
復制代碼 代碼如下:
4月26日在<span style="color:#C03">
主站蜘蛛池模板:
国产网站免费视频
|
久久中文字幕免费
|
国产成人精品免费视频大全可播放的
|
国产成人在线播放视频
|
伊人久久大香线蕉久久婷婷
|
二级片毛片
|
91在线视频福利
|
青青草久久伊人
|
一区二区三区免费视频 www
|
999精品免费视频观看
|
四虎国产精品永久地址99
|
黄色片在线观看网站
|
国产福利写真视频在线观看
|
精品伊人久久久香线蕉
|
97视频久久久
|
精品孕妇一区二区三区
|
国产亚洲精品拍拍拍拍拍
|
国产精品亚洲片在线花蝴蝶
|
欧美视频精品
|
免费毛片在线视频
|
国产手机在线播放
|
桃花综合久久久久久久久久网
|
一个人免费播放在线视频看片
|
小泽玛利亚一区二区三区免费
|
中文字幕一区二区三区四区五区人
|
一本色道久久88加勒比—综合
|
国产高清国内精品福利
|
99久久精品国产免看国产一区
|
国产第一页精品
|
亚洲香蕉网久久综合影院3p
|
久久国产影视免费精品
|
国产精品久久久久久久9999
|
久久精品免视国产
|
色悠综合
|
天天做天天做天天综合网
|
优优色影|
欧美大成色www永久网站
|
99在线视频免费
|
国产一区二区网站
|
久久久久青草大香线综合精品
|
国产精品亚洲第一区焦香
|