天天躁日日躁狠狠躁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">

主站蜘蛛池模板: 忘忧草在线影院WWW日本动漫 | 亚洲三级黄色 | 被滋润的艳妇疯狂呻吟白洁老七 | 亚欧成人毛片一区二区三区四区 | 中文字幕不卡在线高清 | 97在线视频免费人妻 | 国内精品久久久久久西瓜色吧 | 亚洲精品无夜久久久久久久久 | 99久久国产露脸精品国产麻豆 | 国产精品999 | 国产午夜福利100集发布 | 久啪久久全部视频在线 | 国产最新精品亚洲2021不卡 | 久久精品亚洲精品国产欧美 | 久久精品无码人妻无码AV蜜臀 | 57PAO强力打造高清免费 | 国产麻豆精品久久一二三 | 99久久国产极品蜜臀AV酒店 | 国产亚洲欧美日韩综合综合二区 | 99麻豆精品国产人妻无码 | 免费精品一区二区三区在线观看 | 超碰97人人做人人爱网站 | 国产午夜精品美女免费大片 | 99久久国产综合精品国 | 2021国产精品视频一区 | 国产精品99久久久久久宅男AV | 韩国电影久久 | 果冻传媒在线观看视频 | 成人做视频免费 | 日本69xxxx | 午夜亚洲精品不卡在线 | 精品国产乱码久久久久久夜深人妻 | 欧美整片华人play | 国产精品99久久久久久人韩国 | 中字幕久久久人妻熟女天美传媒 | 潮 喷女王cytherea | 18亚洲男同gay1069| 高清国产免费观看视频在线 | 亚洲精品久久久久一区二区三 | 嫩草影院地址一二三 | 视频一区亚洲视频无码 |