1

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

2
  • tried SimpleXML? check this Basic SimpleXML usage Commented Aug 14, 2014 at 3:35
  • Tried but the xml which i am using does not have separate tags for each item. Commented Aug 14, 2014 at 3:52

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.