PHP file_get_contents特定编码 [英] PHP file_get_contents specific encoding
本文介绍了PHP file_get_contents特定编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在PHP中有一个与file_get_contents有关的特殊问题,这里是代码:
i have one special issue with file_get_contents in PHP, here is code:
$html = file_get_contents("http://www.bratm.sk/trochu-harlem-inspiracie-zaslite-nam-svoj-super-harlem-shake-ak-bude-husty-zverejnime-ho");
它给我这样的东西
í}KsŰĆŇčÚŽň!Ç& zRŚ|iI[#)öIkI ĆĺăĹŮÝĹÍý_ŐŃâ[EVßîV%Ů˙ëvĎ ř)śG#óčééééÇĚ çáÜöÁÖÉ;¤áˇ,rřĂăçť[DQ5íeaKÓśOśÉ?ě='šL¸ÔöLßä6ľ4mg_!JĂ÷˘Śu:L§án];9ŇÎV+ި1|C
在这个页面的某些页面,我可以得到正确的编码和内容与iconv,但在这里im无奈,我该如何解决这个问题? thx
in some pages from this page i can get proper encoding and content with iconv, but here im helpless, how can i fix that? thx
推荐答案
使用cURL。这个函数是file_get_contents的替代方法。
Use cURL. This function is an alternative to file_get_contents.
function url_get_contents($Url) {
if (!function_exists('curl_init')){
die('CURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
$data = url_get_contents("http://www.bratm.sk/trochu-harlem-inspiracie-zaslite-nam-svoj-super-harlem-shake-ak-bude-husty-zverejnime-ho/");
print_r($data);
这篇关于PHP file_get_contents特定编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文