中文字幕日韩一区二区_国产一区二区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久久久久久久久久久久久 | 欧美中文字幕 | 色网在线播放 | 色桃网 | 九热在线 | 91影视 | 国产乱肥老妇国产一区二 | 国产婷婷色一区二区三区 | av大片在线 | 日本成年免费网站 | 日韩电影一区二区三区 | 国产精品一区在线 | 黄色成人av | 午夜激情在线 | 波多野结衣一区二区 | 国产羞羞视频在线观看 | 欧美视频区 | 亚洲精品第一国产综合野 | 国产激情自拍视频 | 怡红院免费的全部视频 | 国产精品嫩草影院精东 | 国产午夜精品久久久久 | 久久精品国产一区二区电影 | 91精品中文字幕一区二区三区 | 中文字幕人成乱码在线观看 | 麻豆久久久9性大片 | 欧美一区二区三区的 | 免费观看一区二区三区毛片 | 一级做a爰片性色毛片16美国 | 午夜视频网 | 一级a毛片 | 91视频导航 | 欧美日韩亚洲系列 | 日韩在线中文字幕 | 成人毛片视频免费 | 九色91视频 | 美女爽到呻吟久久久久 | 亚洲国产精品日本 | 国产一区免费视频 |