Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #17552 > unrolled thread
| Started by | alex <1j9448a02@lnx159sneakemail.com.invalid> |
|---|---|
| First post | 2017-07-25 09:19 +0200 |
| Last post | 2017-07-26 13:11 +0200 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.php
view rss item content alex <1j9448a02@lnx159sneakemail.com.invalid> - 2017-07-25 09:19 +0200
Re: view rss item content "J.O. Aho" <user@example.net> - 2017-07-25 18:31 +0200
Re: view rss item content alex <1j9448a02@lnx159sneakemail.com.invalid> - 2017-07-26 13:11 +0200
| From | alex <1j9448a02@lnx159sneakemail.com.invalid> |
|---|---|
| Date | 2017-07-25 09:19 +0200 |
| Subject | view rss item content |
| Message-ID | <ol6re6$14jp$1@gioia.aioe.org> |
<?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?
[toc] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2017-07-25 18:31 +0200 |
| Message-ID | <etpa38Fd3ssU1@mid.individual.net> |
| In reply to | #17552 |
On 07/25/17 09:19, alex wrote:
> <?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?
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
[toc] | [prev] | [next] | [standalone]
| From | alex <1j9448a02@lnx159sneakemail.com.invalid> |
|---|---|
| Date | 2017-07-26 13:11 +0200 |
| Message-ID | <ol9tdc$1r4d$1@gioia.aioe.org> |
| In reply to | #17553 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web