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

主站蜘蛛池模板: 成人天堂婷婷青青视频在线观看 | 一二三区乱码不卡手机版 | 欧美末成年videos丨 | 青青久在线 | 男女交性视频无遮挡全过程 | 2019午夜75福利不卡片在线 | 欧洲最大无人区免费高清完整版 | 亚洲一区免费观看 | 叔叔 电影完整版免费观看韩国 | 亲爱的妈妈6韩国电影免费观看 | 5g在线视讯年龄确认海外禁止进入 | 久久精品免视看国产 | 闺蜜扒开我尿口使劲揉 | 99re热视频这里只有精品 | 国产亚洲精品V在线观看一 国产亚洲精品a在线观看app | 最近的2019中文字幕HD | 中文字幕一区在线观看视频 | 爱情岛论坛网亚洲品质 | 大相蕉伊人狼人久草av | 秋霞电影院午夜伦高清 | 精品人妻一区二区三区视频53 | 亚洲精品国产高清嫩草影院 | 亚洲日本欧美产综合在线 | 久久88综合 | 经典三级四虎在线观看 | 国产日韩在线欧美视频 | 秋霞最新高清无码鲁丝片 | 伊人青青久 | 99无码熟妇丰满人妻啪啪 | 91久久综合精品国产丝袜长腿 | 口工漫画r18全彩啪啪 | 全免费A敌肛交毛片免费懂色AV | 麻婆豆腐传媒视频免费 | 黑粗硬大欧美在线视频 | 亚洲人成无码久久久AAA片 | 116美女写真成人午夜视频 | 在教室伦流澡到高潮HNP视频 | 伊人久久大香线蕉资源 | 国产嫩草影院精品免费网址 | 交换邻居波多野结衣中文字幕 | 蜜桃成人在线 |