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

主站蜘蛛池模板: 少妇无套内谢久久久久 | 国产欧美一区二区三区免费 | 99香蕉精品视频在线观看 | 99视频在线观看视频 | 60岁老年熟妇在线无码 | 热久久国产欧美一区二区精品 | 国产成人无码精品久久久影院 | 国产精品无码亚洲精品 | 久久这里只精品国产99re66 | 国产人妻精品午夜福利免费不卡 | 国产中文字幕乱码一区 | 久久免费看视频 | 亚洲精品永久免费 | 亚洲一区乱码电影在线 | 婷婷综合亚洲爱久久 | 午夜欧洲亚洲AV永久无码精品 | 在线观看中文字幕国产 | 百度影音第四色 | 国产69精品久久久久乱码 | 国产AV精品国语对白国产 | 亲胸吻胸添奶头GIF动态图免费 | 在线播放一区二区精品产 | 美女隐私黄www视频 美女议员被泄裸照 | 动漫美女被吸奶 | 亚洲三级在线看 | 国产精品久免费的黄网站 | 亚洲 欧美 国产 在线 日韩 | 欧美高清vivoesosexo18 | 亚洲一卡二卡三卡四卡2021麻豆 | 91麻豆国产精品91久久久 | 亚洲偷自拍精品视频在线观看 | 伊人影院网 | 国产精品涩涩涩视频网站 | 国产人妖一区二区 | 亚洲视频 在线观看 | 办公室激情在线观看 | 久久re这里精品在线视频7 | 深夜释放自己在线观看 | 国产传媒麻豆剧精品AV | ccc36色小姐电影| 乱爱性全过程免费视频 |