Deoctor Posted December 8, 2009 Share Posted December 8, 2009 Hai i need to fetch the following data from the xml which i have attached as text file channel->title channel->item->text i have written the code in the following way but it is not working can any one help me out <?php $url='http://chaitu09986025424.blog.co.in/feed/rss/'; $xml = file_get_contents($url); $fh = fopen("test.xml", 'w'); fwrite($fh, $xml); $objDOM = new DOMDocument(); $objDOM->load("test.xml"); //make sure path is correct $channel = $objDOM->getElementsByTagName("channel"); // for each note tag, parse the document and get values for // tasks and details tag. foreach( $channel as $value ) { $titles = $value->getElementsByTagName("title"); $title = $titles->item(0)->nodeValue; $details = $value->getElementsByTagName("description"); $detail = $details->item(0)->nodeValue; echo "$task <br> $detail <br>"; $item=$objDOM->getElementsByTagName("item"); foreach($item as $value1) { $titles_item=$value1->getElementsByTagName("title"); $tit_item=$titles_item->item(0)->nodevalue; echo "hee<br>".$tit_item; } } ?> [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/184400-help-with-xml-reading/ Share on other sites More sharing options...
kopytko Posted December 8, 2009 Share Posted December 8, 2009 This will fetch title and description from xml file. <?php $xml = new SimpleXMLElement('http://chaitu09986025424.blog.co.in/feed/rss/', 0, true); $data = array(); foreach($xml->channel->item as $item) { $i = count($data); $data[$i]['title'] = (string)$item->title; $data[$i]['description'] = (string)$item->description; } var_dump($data); Link to comment https://forums.phpfreaks.com/topic/184400-help-with-xml-reading/#findComment-973709 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.