I’m trying to read and store an RSS feed in my database using this method.
<?php
$homepage = file_get_contents('http://www.forbes.com/news/index.xml');
$xml = simplexml_load_string($homepage,'SimpleXMLElement', LIBXML_NOCDATA);
echo '<pre>';
print_r('$xml');
?>
But:
1. How can I check if `$homepage` contains a valid XML file or not?
2. I'm want to know how much time its taken to call if the url is valid XML file
$homepage = file_get_contents('http://www.forbes.com/news/index.xml');
using try and catch exceptions..
Try something like this
Edit: You can even combine the
file_get_contents()call andSimpleXMLElementcreation into one line usingthough any timing you wrap around that line will include HTTP retrieval and parsing