Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

view rss item content

5 views
Skip to first unread message

alex

unread,
Jul 25, 2017, 3:19:44 AM7/25/17
to
<?php // test.php

$extended_format=true;// turn on extended view

// first item getting
$_ =
simplexml_load_file('http://feeds.bbci.co.uk/news/rss.xml?edition=uk')->
channel->
item[0]
;

echo
"<h3>" . $_->title .' - ' . $_->link . "</h3>\n",
$extended_format ?
$_->children(
"content",
true
) :
$_->description
;

?>



$ php test.php

<h3>Charlie Gard: 'Last precious moments' for parents with their son -
http://www.bbc.co.uk/news/uk-england-london-40712913</h3>

Because "content" is missing?

J.O. Aho

unread,
Jul 25, 2017, 12:31:47 PM7/25/17
to
Did you look at the xml?

<item>
<title><![CDATA[Parents plea to take Charlie home]]></title>
<description><![CDATA[Chris Gard and Connie Yates's lawyer
accuses the hospital of "putting up obstacles".]]></description>

<link>http://www.bbc.co.uk/news/uk-england-london-40716292</link>
<guid
isPermaLink="true">http://www.bbc.co.uk/news/uk-england-london-40716292</guid>
<pubDate>Tue, 25 Jul 2017 13:58:55 GMT</pubDate>
<media:thumbnail width="976" height="549"
url="http://c.files.bbci.co.uk/1132F/production/_97074407_mediaitem97074405.jpg"/>
</item>

There ain't any content, also there ain't multiple instances of the same
"name" in the item object, so no need to use the children() function.


I suggest you also switch the name of the variable, as it will be a lot
easier on you when you come back to old code. Keep in mind that the code
is run on the server side, so short variable names will not mean less
data is sent to the user.

--

//Aho

alex

unread,
Jul 26, 2017, 7:11:51 AM7/26/17
to
Il 25/07/2017 18:31, J.O. Aho ha scritto:
> On 07/25/17 09:19, alex wrote:
> [...]

I understand the problem, thank you
0 new messages