Reputation: 689
I am working on an multi-rss reader, which basically imports feed from blogs and social media and put them in a timeline. A global social activity report :)
I cant use direct url open on my webserver, so I had to change the script to retrieve the rss feed per curl.
Strange, when I open the rss-feed on local with the load() method, I receive the correct Object. But when I am using cURL to open it, the textContent is empty in the Object. Why this?
Here the code to grab the xml-data
foreach ($FeedUrls as $FeedUrl) {
$rss = new DOMDocument();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $FeedUrl['url']);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$rsscurl = curl_exec($ch);
curl_close($ch);
$rss->load($rsscurl);
I am getting no curl error with output of curl_error()
The two objects look slight different, I noticed. The
documentURI and baseURI are filled when not using cURL. But there is no cURL error?
If I print_r the $rsscurl, I see the xml code with the blog posts from the rss feed. But if I print the $rss object after the DOMDocument load, I see the object without the content. ???
What am I missing here?
Upvotes: 0
Views: 1007
Reputation: 689
Aww I found the problem
When loading the rss feed with curl, I have to use the loadXML() method instead of load() in the DOMDocument!!
load() loads from file, and loadXML() from string, so the cURL is returning a string, and not a file!
I do not fully understand why I did not get any error on this
Upvotes: 1