一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

PHP解析html類庫simple_html_dom的轉(zhuǎn)碼bug

這幾天有在用simple_html_dom抓一些文章。不同網(wǎng)站的編碼在國內(nèi)基本上是gbk gb2312 utf-8。而以gb2312和utf-8居多。

我這一版的simple_html_dom有一個方法 convert_text 是這個樣子的。

復(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;
 }

來看這一行:

復(fù)制代碼 代碼如下:
    $converted_text = iconv($sourceCharset, $targetCharset, $text); 

會引起轉(zhuǎn)碼不正確。比如會把gb2312的文字轉(zhuǎn)成:

復(fù)制代碼 代碼如下:
4月26日在<span style="color:#C03">

主站蜘蛛池模板: 午夜视频网站在线观看 | 国产精品久久久亚洲456 | 亚洲国产成人99精品激情在线 | 久久99国产乱子伦精品免 | 欧美成人福利视频 | 成人性a激情免费视频 | 日韩精品亚洲专区在线影视 | 国产精品久久久久无毒 | 久久91视频| 91一个人的在线观看www | 天天色踪合 | 欧美人成网站免费大全 | 美女视频黄.免费网址 | 亚洲国产成人久久午夜 | 国产精品一级片 | 日本欧美一区二区三区视频麻豆 | 久久大香线蕉综合爱 | 欧美成人综合在线观看视频 | 午夜欧美福利视频 | 国产亚洲精品视频中文字幕 | 91麻豆精品国产91久久久 | 欧美特黄特色aaa大片免费看 | 四虎最新网 | 在线观看中文字幕国产 | 精品国精品自拍自在线 | 绝对真实国产乱 | 激情五月婷婷丁香 | 国产一区二区三区久久精品 | 综合成人在线 | 97视频久久久 | 国产麻豆91 | 黄色影院7755 | 青春娱乐国产分类精品二 | 视频三区 | 色噜噜狠狠狠综合曰曰曰88av | 成年人视频免费在线播放 | 欧美成人午夜视频免看 | www.色.con| 色综合久久婷婷天天 | 日本三区 | 在线成人亚洲 |