一区二区久久-一区二区三区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 | 伊人网在线免费视频 | 久久久噜久噜久久综合 | 精品九九久久 | 欧美色惰 | 国产精品欧美一区二区在线看 | 中文乱码精品一区二区三区 | 国产成人精视频在线观看免费 | xxxxxbbbbb欧美性极品 | 国产在线播放91 | 国产麻豆网| 在线一区二区观看 | 亚洲狠狠97婷婷综合久久久久 | 五月婷六月丁香 | 国产女同一区二区在线 | china精品对白普通话 | xf在线a精品一区二区视频网站 | 中文字幕一区二区三区免费视频 | 涩在线| 国产原创中文视频 | 欧美一区二区三区精品国产 | 丁香视频在线观看播放 | 国产综合久久久久久 | 黄 色 片 在 线 看 | 日本成人一区二区三区 | 在线视频一区二区三区四区 | 一区二区三区中文字幕 | 香蕉免费看一区二区三区 | 国产精品免费大片 | 久久亚洲私人国产精品 | 午夜在线观看视频免费 成人 | 亚洲线精品一区二区三区 | 久久成人精品 | 亚洲综合三区 | 91精品福利在线观看 | 五月天激情社区 | 国产精品极品美女自在线观看免费 | 亚洲精品无码专区在线播放 | 精新精新国产自在现 | 日本福利片国产午夜久久 |