我正在尝试使用 CURL 从我的 wordpress 博客中检索 XML 数据。
这是我的PHP:
$ch = curl_init("http://www.hazelandruby.com/blog/feed");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/xml') );
$data = curl_exec($ch);
print_r(curl_getinfo($ch));
curl_close($ch);//close connection
unset($ch);
var_dump($data);
$data
是一个空字符串。
curl_getInfo
给我这个信息:
Array ( [url] => http://www.hazelandruby.com/blog/feed [content_type] => text/html [http_code] => 301 [header_size] => 335 [request_size] => 99 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.039749 [namelookup_time] => 0.001784 [connect_time] => 0.001862 [pretransfer_time] => 0.001866 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => 0 [starttransfer_time] => 0.03974 [redirect_time] => 0 [certinfo] => Array ( ) [redirect_url] => http://www.hazelandruby.com/blog/feed/ )
您可以访问 XML 文件本身:http ://www.hazelandruby.com/blog/feed/
最终,我希望能够用它创建一个 SimpleXmlElement,但它不起作用。我的 PHP 对吗?wordpress 是否输出正确的 XML?如果不是(我不想改变 wordpress 正在做什么),我如何将 url 解释为 XML 并获取数据?