php - How can i get XML data from the dictionary -


below xml format:

    <item>                 <title>lorem ipsum</title>                 <link>http://www.website.com</link>                 <pubdate>sun, 30 aug 2015 16:51:18 +0000</pubdate>                 <description>                     <![cdata[dummy text dummy text dummy text]]>                 </description>                  <title>lorem ipsum test</title>                 <link>http://www.test.com</link>                 <pubdate>sun, 29 aug 2015 16:51:18 +0000</pubdate>                 <description>                     <![cdata[dummy text test dummy text test dummy text test]]>                 </description>     </item> 

what have tried:

    <?php     $rss = file_get_contents('<url>');     $xml = new simplexmlelement($rss);     foreach($xml->channel->item $feed){         $title = $feed->title;         $added_date_time = date("y-m-d h:i:s", strtotime($date));         $description = $feed->description;         print_r($title);         print_r($description);     }     ?> 

it giving me output description:

simplexmlelement object ( [0] => simplexmlelement object ( ) ) 

how can description data?

you can try php:s simplexml: load xml, access element

$items = new simplexmlelement($xmlstring); echo $items->description; 

edit: ok, see have changed xml in question now, solution should still work. code echoes "dymmy..." on sandbox too: http://sandbox.onlinephpfunctions.com/ in description missing, or running strange system. can alternatively try loading of sring (should convert cadata objects clean strings)

$items = simplexml_load_string($xmlstring, 'simplexmlelement', libxml_nocdata); 

further, can try cast element getting strin:

echo (string) $items->description; 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -