一区二区久久-一区二区三区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">

主站蜘蛛池模板: 国产精品嫩草影院一二三区 | 久久国产成人亚洲精品影院老金 | 91精品视频观看 | 国产极品在线观看视频 | 午夜视频免费国产在线 | 国产成人精品日本亚洲网站 | 天天做天天爱夜夜爽女人爽宅 | 国产精品久久久久久亚洲小说 | 日韩精品一区二区三区国语自制 | 激情小视频网站 | 女人一级一级毛片 | 在线看的黄色网址 | 亚洲小说图片区 | 欧美日韩一区二区亚洲 | 热99re久久精品香蕉 | 四虎永久在线日韩精品观看 | 欧美日韩亚洲国产一区二区三区 | 五月婷婷婷婷 | 黄色短视频免费观看 | www.日本视频| 永久免费视频 | 中文字幕一区在线观看 | 成人免费看黄网站yyy456 | 久久久久久噜噜噜久久久精品 | 免费网站看黄 | 秋霞伊人网 | 天天色图片 | 精品国偷自产在线 | 亚洲小说欧美激情另类 | 欧美视频在线看 | 国产精品视频一区牛牛视频 | 国产一区中文字幕在线观看 | 伊人久久综合谁合综合久久 | 久久久久久久久影院 | 成人免费大片a毛片 | 色涩网站在线观看 | 欧美人与物另类 | 91中文字幕yellow字幕网 | 久久综合一区 | 网红毛片| 欧美性高清在线视频 |