Reputation: 8791
I'm trying to get RSS feed with tag , but the always gets reduced to a small part of the text continued by "...". I already checked this topic but I got no results as I expected. This is the feed I'm trying to parse:
https://bus237d201smartphones.wordpress.com/feed/
And this is my code:
function resolveFile($file_or_url) {
if (!preg_match('|^https?:|', $file_or_url))
$feed_uri = $_SERVER['DOCUMENT_ROOT'] .'/shared/xml/'. $file_or_url;
else
$feed_uri = $file_or_url;
return $feed_uri;
}
$file_or_url='https://bus237d201smartphones.wordpress.com/feed/';
$file_or_url = resolveFile($file_or_url);
if (!($x = simplexml_load_file($file_or_url)))
return;
foreach ($x->channel->item as $item)
{
$content = $item->children("content", true);;
echo("<br>");
echo("content <br>");
print_r($content);
$e_encoded = $content->encoded;
echo("<br>");
echo("encoded <br>");
print_r($e_encoded);
}
This is browser output:
content
SimpleXMLElement Object ( [encoded] => SimpleXMLElement Object ( ) )
encoded
SimpleXMLElement Object ( [0] => SimpleXMLElement Object ( ) )
Google made the Android operating system for all kinds
of handheld devices (Smartphones and PC Table...
What is wrong with it?
Upvotes: 0
Views: 59
Reputation: 5524
If you try to get content of element <content:encoded>
where content is namespace xmlns:content="http://purl.org/rss/1.0/modules/content/"
, you can do it with this code:
<?php
function resolveFile($file_or_url) {
if (!preg_match('|^https?:|', $file_or_url))
$feed_uri = $_SERVER['DOCUMENT_ROOT'] .'/shared/xml/'. $file_or_url;
else
$feed_uri = $file_or_url;
return $feed_uri;
}
$file_or_url='https://bus237d201smartphones.wordpress.com/feed/';
$file_or_url = resolveFile($file_or_url);
if (!($x = simplexml_load_file($file_or_url)))
return;
foreach ( $x->getNameSpaces( true ) as $key => $children ) {
$$key = $x->children($children);
}
foreach ($x->channel->item as $item)
{
$childrenContent = $item->children('http://purl.org/rss/1.0/modules/content/');
$encodedContent = $childrenContent->encoded->__toString();
echo("<br>");
echo("encoded <br>");
print_r($encodedContent);
}
Upvotes: 1