|
這幾天有在用simple_html_dom抓一些文章。不同網(wǎng)站的編碼在國(guó)內(nèi)基本上是gbk gb2312 utf-8。而以gb2312和utf-8居多。
我這一版的simple_html_dom有一個(gè)方法 convert_text 是這個(gè)樣子的。
復(fù)制代碼 代碼如下:
// 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;
}
來(lái)看這一行:
復(fù)制代碼 代碼如下:
$converted_text = iconv($sourceCharset, $targetCharset, $text);
會(huì)引起轉(zhuǎn)碼不正確。比如會(huì)把gb2312的文字轉(zhuǎn)成:
復(fù)制代碼 代碼如下:
4月26日在<span style="color:#C03">
主站蜘蛛池模板:
日韩中文字幕在线亚洲一区
|
国产精品久久99
|
久久精品国产夜色
|
国产精品成人嫩妇
|
国产免费一区2区3区4区
|
91精品国产高清久久久久久io
|
91麻豆精品一二三区在线
|
久久九九综合
|
好吊妞在线观看
|
97久久精品国产精品青草
|
1区2区
|
天天影院色
|
久久网站免费
|
国产麻豆网站
|
伊人久久成人成综合网222
|
国产91在线精品福利
|
加勒比免费视频
|
91原创视频在线观看
|
欧美xxxxxxxx
|
99久在线精品99re6视频
|
日本zzzwww大片免费
|
另类视频综合
|
婷婷狠狠干
|
美女网站视频色
|
国产综合视频在线观看
|
婷婷97狠狠的狠狠的爱
|
91九色麻豆
|
91在线视频播放
|
成年人激情网
|
sifangtv
|
国产精品久久久久久一级毛片
|
亚色在线播放
|
亚洲精品无码专区在线播放
|
日日摸人人看97人人澡
|
欧美三级黄视频
|
亚洲网站视频
|
国产精品999在线
|
亚欧美视频
|
国产有码视频
|
超高清欧美videos360
|
怡红院成人g影院
|