0

我想使用 php 从远程服务器获取 xml 数据。这是我获取 xml 的代码,但我得到了 bool(false)

<?php 
   header ("content-type: text/plain");
   $filename = file_get_contents("http://gep4.com/radio/wp-content/plugins/haze_radio/readme.txt");
   var_dump($filename);
?>
4

3 回答 3

0

试试这个来获取它正在工作的数据

function getPage($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com/');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8');

$result['EXE'] = curl_exec($ch);
$result['INF'] = curl_getinfo($ch);
$result['ERR'] = curl_error($ch);

curl_close($ch);
 unset($url, $referer, $agent, $header, $timeout);
return $result;
}
$url = "http://gep4.com/radio/wp-content/plugins/haze_radio/readme.txt";
var_dump(getPage($url) );
于 2012-11-05T12:22:50.590 回答
0

这意味着获取文件内容时出错。您是否确定该文件存在或您有权读取该文件或其他内容?

文件获取内容

返回值

该函数返回读取的数据或失败时返回 FALSE

于 2012-11-05T12:00:01.287 回答
0

可能allow_url_fopen在 php.ini 中被禁用

如果您有权访问 php.ini,请启用它

或者,尝试CURL

示例 CURL 调用

    $ch = curl_init(); 

    // set url 
    curl_setopt($ch, CURLOPT_URL, "example.com"); 

    //return the transfer as a string 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    // $output contains the output string 
    $output = curl_exec($ch); 

    // close curl resource to free up system resources 
    curl_close($ch); 
于 2012-11-05T12:00:22.410 回答