binu j
binu j

Reputation: 399

Parsing the xml using PHP

Parsing the following xml.

http://www.livehindustan.com/home/rssfeed/1.html

i tried with simplepie, but it returns error. Any other custom way to extract the guid, pubDate, bigimage of the items in the xml feed using PHP

Upvotes: 1

Views: 37

Answers (1)

bansi
bansi

Reputation: 56982

Try this

<?php
$xmlstr = file_get_contents("http://www.livehindustan.com/home/rssfeed/1.html");
$xml = new SimpleXMLElement(trim($xmlstr));
foreach ($xml->channel->item as $item) {
   echo 'guid =>', $item->guid, PHP_EOL, 
    ' pubDate => ', $item->pubDate, PHP_EOL,
    ' bigimage => ', $item->bigimage, PHP_EOL, PHP_EOL;
}

Note: I have used trim($xmlstr) because your feed contains a blank line at the beginning, which is not valid for XML.

Upvotes: 1

Related Questions