pc-magas / phpquery

Automatically exported from code.google.com/p/phpquery
0 stars 0 forks source link

when program is utf-8,but remote page is gbk , the wrong has occur #232

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
My program is utf-8 no bom encode,i get remote site is gbk encode,ex 
http://tieba.baidu.com/f?ie=utf-8&kw=奇迹篮球

my code is :
<code>
$url="http://tieba.baidu.com/f?ie=utf-8&kw=奇迹篮球";
phpQuery::newDocumentFileHTML($url,'gbk');
$t = pq('title')->html();

echo mb_detect_encoding ($t);// result is : UTF-8
echo $t; // this is  unreadable code
</code>

i try some function ... but not find .. so i write a function 
<code>
function d_di8_open( $url )
{
    $cnt = file_get_contents($url);
    return mb_convert_encoding($cnt ,"UTF-8","GBK");
}
$url="http://tieba.baidu.com/f?ie=utf-8&kw=奇迹篮球";
phpQuery::newDocumentHTML( d_di8_open($url) );  
$t = pq('title')->html();

echo mb_detect_encoding ($t);// result is : UTF-8
echo $t; // this is right
</code>

so i think phpquery had a bug ....

Original issue reported on code.google.com by envilwind@gmail.com on 26 Aug 2013 at 11:08