中文字幕日韩一区二区_国产一区二区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">

主站蜘蛛池模板: 自拍在线 | 日韩影院在线观看 | av一级久久 | 国产精品成人一区二区三区 | 精品视频一区二区 | 中文天堂在线一区 | 久久久精品网站 | 美人の美乳で授乳プレイ | 国产日韩欧美在线一区 | 久久不卡 | 中文字幕电影在线观看 | 伊人网国产 | 亚洲福利av| 自拍偷拍小视频 | 青青草国产在线观看 | 黄色一级免费 | 在线只有精品 | 成人免费av在线 | 亚洲不卡在线视频 | 欧美一区二区三区在线观看视频 | 久操伊人 | 日本一区不卡 | 国产精品久久久久久av公交车 | 亚洲成人日韩 | 欧美一区二区三区久久精品 | 伊人爽 | 男人av在线播放 | 美日韩免费视频 | 成人福利电影 | 午夜在线小视频 | 午夜精品在线观看 | 9191av| 久久久激情视频 | 亚洲国产网 | 久久精品福利视频 | www.久久久久久久久久久久 | 亚洲一区二区三区在线观看免费 | 亚洲精品成人在线 | 国产乱人伦精品一区二区 | 国产在线拍偷自揄拍视频 | 久久久www成人免费无遮挡大片 |