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

主站蜘蛛池模板: 韩国和日本免费不卡在线 | 777午夜精品久久AV蜜臀 | 边做边爱免费视频 | 国语自产拍大学生在线观看 | yin荡体育课羞耻play双性 | 韩国女主播内部vip自带氏巾 | 久久精品无码人妻无码AV蜜臀 | 亚洲精品卡2卡3卡4卡5卡区 | 男总裁憋尿PLAY灌尿BL | 羞羞影院男女爽爽影院尤物 | 99国内精品久久久久久久清纯 | 青青娱乐网 | 久久精品亚洲AV无码三区观看 | 亚洲精品无码一区二区三区四虎 | 国产亚洲欧美日韩综合综合二区 | 亚洲欧美日本国产在线观18 | 国产乱色伦影片在线观看 | 国产性色AV内射白浆肛交后入 | 日本国产精品无码一区免费看 | 久久婷婷丁香五月色综合啪免费 | 狠狠色香婷婷久久亚洲精品 | 青柠视频在线观看高清HD | 《乳色吐息》无删减版在线观看 | 韩国和日本免费不卡在线 | 国产在线观看91精品 | 最近更新2019中文字幕国语 | 伊人久久综在合线影院 | 亚洲欧洲日本无在线码播放 | 久久综合老色鬼网站 | 性色欲情网站IWWW九文堂 | A级毛片高清免费网站不卡 a级毛片高清免费视频 | 国产人妻麻豆蜜桃色在线 | 青青草国产精品久久 | 爽死你个放荡粗暴小淫货漫画 | 羲义嫁密着中出交尾gvg794 | 香蕉AV福利精品导航 | 99热精品一区 | 少妇无码太爽了视频在线播放 | 国产精品无码无卡毛片不卡视 | 亚洲va久久久久 | AV一区AV久久AV无码 |