Код прост:
<?php
function getStringFromUrl($url){
$fResource = fopen($url, 'r');
do {
$data = fread($fResource, 8192);
if (strlen($data) == 0) {
break;
}
$contents .= $data;
} while(true);
fclose ($fResource);
$contents = mb_convert_encoding($contents,'utf-8','gbk');
return $contents;
}
echo getStringFromUrl(urlencode('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=text&ip=119.97.23.59'));
echo file_get_contents('http://blog.sina.com.cn/rss/1400122351.xml');
Иногда я могу получать контент, иногда нет. Я не могу понять, почему.
(РЕДАКТИРОВАТЬ: сообщение об ошибке: [function.fopen]: не удалось открыть поток и [function.file-get-contents]: не удалось открыть поток )
Конечно, доступны 2 вышеуказанных URL.
Я также установил allow_url_fopen = On
в php.ini.