在php中从远程服务器获取xml数据

在php中从远程服务器获取xml数据,php,jquery,xml,Php,Jquery,Xml,我想使用php从远程服务器获取xml数据。这是我获取xml的代码,但我得到了bool(false) 这意味着获取文件内容时出错。您是否确保该文件存在,或者您有权读取该文件或其他内容 返回值 函数在失败时返回读取数据或FALSE 可能在php.ini中被禁用 如果您可以访问ot php.ini,请启用它 或者,试试看 示例CURL调用 $ch = curl_init(); // set url curl_setopt($ch, CURLOPT_URL, "examp

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


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

返回值

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

可能在php.ini中被禁用

如果您可以访问ot php.ini,请启用它

或者,试试看

示例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); 

尝试此操作以获取正在工作的数据

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) );

真卷曲。也许远程服务器需要头信息…文件在另一台服务器上,但是否有其他方法可以在php或jquery plz帮助中获取xml数据这是在php中获取文件内容的最简单方法,我认为您需要首先解决这个问题。在浏览器中键入文件,您可以访问它吗?其他方法有
fopen
curl
。看看其他答案
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) );