中文字幕日韩一区二区_国产一区二区av_国产毛片av_久久久久国产一区_色婷婷电影_国产一区二区精品

PHP解析html類庫simple_html_dom的轉碼bug

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

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

復制代碼 代碼如下:
 // 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;
 }

來看這一行:

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

會引起轉碼不正確。比如會把gb2312的文字轉成:

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

主站蜘蛛池模板: 人人人人干 | 国产精品毛片一区二区在线看 | 精品一二三 | 国产一级一级毛片 | 91偷拍精品一区二区三区 | 国产精品久久二区 | 婷婷色婷婷 | 最新国产精品 | 久久久久精 | 国产成人av一区二区三区 | 欧美日韩不卡 | 波多野结衣二区 | 久久国产综合 | 日韩毛片在线视频 | 亚洲一区国产精品 | 日韩一级免费电影 | 欧美日韩在线播放 | 久久久视频在线 | 国偷自产av一区二区三区 | 日韩欧美精品在线播放 | 国产高清一区二区 | 先锋资源吧 | 在线免费观看毛片 | 久久日韩精品一区二区三区 | 国产精品免费一区二区三区四区 | 久久99精品视频 | 国产精品一区二区视频 | 偷拍自拍网址 | 91欧美| 一级黄色片网址 | 欧美aaa| 午夜久久久 | 日韩免费视频一区二区 | 日韩乱码在线 | 久久蜜桃av一区二区天堂 | 91精品国产综合久久久久久丝袜 | 一级高清免费毛片 | 成人在线一区二区 | 国产精品美女www | 福利在线观看 | 99re视频在线免费观看 |