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

主站蜘蛛池模板: 0951影音在线 | 国产欧美一区二区三区在线看 | 国产精品99久久久精品无码 | 亚洲免费在线观看 | 国内偷拍夫妻av | 亚洲高清在线视频 | 一级毛片免费在线播放 | 伊人久久青草青青综合 | 国产精品视频人人做人人爽 | 国产精品无码亚洲精品 | 调教美丽的白丝袜麻麻视频 | 开心成人社区 | 国产精品视频在线自在线 | 成人毛片一区二区三区 | 麻豆国产精品va在线观看约 | 韩国精品无码少妇在线观看网站 | 中文字幕午夜乱理片 | 欧美人与动牲交XXXXBBBB免费 | 色琪琪无码成人AV视频 | 暖暖 免费 高清 日本在线 | 特黄特色大片免费播放器9 特黄特黄aaaa级毛片免费看 | 日本一区不卡在线播放视频免费 | 亚洲绝美精品一区二区 | 亚洲精品tv久久久久久久久久 | 99久久国产综合精品国 | 69成人免费视频 | 浪潮色诱AV久久久久久久 | 久久视频在线视频观看精品15 | 成人无码国产AV免费看 | 4480YY旧里番在线播放 | 国产盗摄一区二区三区 | 胸太大被男同桌吃好爽 | 国产精品久久久久久免费播放 | 欧美午夜福利主线路 | 在线观看中文 | 午夜AV亚洲一码二中文字幕青青 | 日韩欧美1区 | 欧美另类老女人 | 小莹的性荡生活 | 一品道门在线观看免费视频 | 国产婷婷午夜无码A片 |