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

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

這幾天有在用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">

主站蜘蛛池模板: 色www情 | 国产成人青草视频 | 天天做天天做天天综合网 | 99国产精品高清一区二区二区 | 久久青青草原精品国产软件 | 国产成人综合视频 | 亚洲人的天堂男人爽爽爽 | 91热精品视频 | 国产成人成人一区二区 | 激情六月丁香婷婷四房播 | 黄色片网站在线免费观看 | 精品视自拍视频在线观看 | 亚洲成a人片在线网站 | 国产精品一区二区免费 | 中文字幕精品视频 | 视频福利在线 | 露脸国产自产拍在线观看 | 免费一区二区三区在线视频 | 五月婷婷啪 | 国产成人亚洲综合小说区 | 天天综合视频网 | 亚洲欧美黄 | 91视频免费观看高清观看完整 | 一级做a爰片久久毛片看看 一级做a爰片久久毛片毛片 | 精品日韩一区二区 | 亚洲第一页在线观看 | 日韩一区二区三区视频在线观看 | 美女福利视频一区 | 黄色网页在线 | 久久福利网 | 四虎永久网址在线观看 | 女人洗澡一级毛片一级毛片 | 成人午夜免费视频 | 综合久久综合 | a级国产乱理论片在线观看 a级国产乱理论片在线观看看 | 成人在线观看视频免费 | 黄色高清视频在线观看 | 91精品91久久久 | 九九综合九九综合 | 热久久国产欧美一区二区精品 | 深爱激情婷婷 |