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

主站蜘蛛池模板: 国产精品一区二区资源 | 99re.05久久热最新地址 | 全部免费特黄特色大片看片 | 久久精品视频在线看99 | 无遮挡h肉3d动漫在线观看 | 男人和女人一级黄色大片 | 欧美巨大xxxx做受高清 | 日本人xxxⅹ18hd19hd | 被六个男人躁到一夜同性 | 热re99久久精品国99热 | swag合集120部| 波多野结衣的AV一区二区三区 | 麻豆文化传媒一区二区 | 亚洲99精品A片久久久久久 | 校花在公车上被内射好舒 | 欧美一级做a爰片免费 | 色偷偷网站| 一本到道免费线观看 | 中文字幕高清在线中文字幕 | 第一会所欧美无码原创 | 国产嫩草影院精品免费网址 | www.狠狠色| 娇妻中日久久持久久 | 日韩高清特级特黄毛片 | 日本性hd | 饥渴的护士自慰被发现 | 久久免费视频1 | 国产人妻人伦精品无码.麻豆 | 国产成人无码AV麻豆 | 捏揉舔水插按摩师 | china男士同性视频tv | 老师机影院 | 国产欧美一区二区精品仙草咪 | 国产精品99久久久精品无码 | 日本免费一区二区三区最新vr | 亚洲精品一二三区区别在哪 | 99热最新在线 | 最新无码国产在线视频9299 | 最近的2019中文字幕国语完整版 | 97午夜伦伦电影理论片 | 精品99久久久久成人网站 |