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
Post a Comment