你为什么使用卷曲?您可以使用file_get_contents()函数轻松加载 xml 数据。
尝试这个:
<pre>
<?php
$xml = simplexml_load_string(
file_get_contents('/blog/feed/'),
'SimpleXMLElement',
LIBXML_NOCDATA
);
print_r($xml);
?>
编辑:这是使用 CURL 的另一种方法(确认工作)
<?php
// CURL HTTP Get Helper Function
function CurlGet($fromUrl)
{
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, $fromUrl);
//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);
// Return Output
return (!empty($output) ? $output : false);
}
// Get XML Data From RSS Feed
$xml_str = CurlGet('http://www.digins.nl/blog/feed/');
// Check If We Have Data
if ($xml_str)
{
// Load XML
$xml = simplexml_load_string($xml_str, 'SimpleXMLElement', LIBXML_NOCDATA);
// Debug
echo '<pre>';
print_r($xml);
echo '</pre>';
}
else
{
// Curl request failed
}
?>
这是我测试时得到的输出:
SimpleXMLElement Object
(
[@attributes] => Array
(
[version] => 2.0
)
[channel] => SimpleXMLElement Object
(
[title] => Digins news
[link] => http://www.digins.nl/blog
[description] => Just another WordPress site
[lastBuildDate] => Thu, 31 Oct 2013 10:24:25 +0000
[language] => en-US
[generator] => http://wordpress.org/?v=3.7.1
[item] => Array
(
[0] => SimpleXMLElement Object
(
[title] => test3
[link] => http://www.digins.nl/blog/test3/
[comments] => http://www.digins.nl/blog/test3/#comments
[pubDate] => Thu, 31 Oct 2013 10:24:25 +0000
[category] => Uncategorized
[guid] => http://www.digins.nl/blog/?p=9
[description] => 3e bericht
)
[1] => SimpleXMLElement Object
(
[title] => hello world 2
[link] => http://www.digins.nl/blog/hello-world-2/
[comments] => http://www.digins.nl/blog/hello-world-2/#comments
[pubDate] => Thu, 31 Oct 2013 10:07:35 +0000
[category] => Uncategorized
[guid] => http://www.digins.nl/blog/?p=5
[description] => Dit is een test bericht
)
[2] => SimpleXMLElement Object
(
[title] => Hello world!
[link] => http://www.digins.nl/blog/hello-world/
[comments] => http://www.digins.nl/blog/hello-world/#comments
[pubDate] => Wed, 25 Sep 2013 21:25:08 +0000
[category] => Uncategorized
[guid] => http://www.digins.nl/blog/?p=1
[description] => Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!
)
)
)
)
如果我更新的 CURL 方法不起作用,那么您的托管服务提供商有问题......请与他们联系,因为当我从开发 PC 运行它时它工作正常。