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

主站蜘蛛池模板: 免费A级毛片无码无遮挡 | 亚洲国产在线精品国自产拍五月 | 51精品国产AV无码久久久密桃 | 老色69久久九九精品高潮 | 国产嫩草影院精品免费网址 | 古代又黄又肉到湿的爽文 | 国产成人a在一区线观看高清 | 内射白浆一区二区在线观看 | 久久久久国产精品美女毛片 | 亚洲伊人久久大香线蕉综合图片 | 色偷偷av男人的天堂 | 中文字幕亚洲欧美日韩2o19 | 国产午夜精品视频在线播放 | 99视频精品全部免费免费观 | 伊人久久伊人 | 日韩欧美中文字幕一区 | 我半夜摸妺妺的奶C了她软件 | 久久电影院久久国产 | 国产高清免费观看 | 国产AV午夜精品一区二区入口 | 3D漫画H精品啪啪无码 | 伊人久久电影院 | 久久re这里视频只精品首页 | av在线观看网站免费 | 男人狂躁进女人免费视频公交 | 欧美阿v在线天堂 | 欧美色图14p | 国产美女久久久久久久久久久 | 57PAO强力打造高清免费 | 亚洲 欧美 国产 伦 综合 | 别停好爽好深好大好舒服视频 | 97在线视频免费播放 | 99蜜桃在线观看免费视频网站 | 玩高中女同桌肉色短丝袜脚文 | 国厂精品114福利电影 | 一本道久在线综合道 | 国产爱豆果冻传媒在线观看视频 | 久久久伊人影院 | 天天拍拍国产在线视频 | 亚洲狠狠网站色噜噜 | 一个人免费视频在线观看 |