Currently, I'm grabbing a remote site's XML feed and saving a local copy on my server to be parsed in PHP.
Problem is how do I go about adding some checks in PHP to see if the feed.xml file is valid and if so use feed.xml.
And if invalid with errors (of which sometimes the remote XML feed somes display blank feed.xml), serve a backup valid copy of the feed.xml from previous grab/save ?
code grabbing feed.xml
<?php
/**
* Initialize the cURL session
*/
$ch = curl_init();
/**
* Set the URL of the page or file to download.
*/
curl_setopt($ch, CURLOPT_URL,
'http://domain.com/feed.xml');
/**
* Create a new file
*/
$fp = fopen('feed.xml', 'w');
/**
* Ask cURL to write the contents to a file
*/
curl_setopt($ch, CURLOPT_FILE, $fp);
/**
* Execute the cURL session
*/
curl_exec ($ch);
/**
* Close cURL session and file
*/
curl_close ($ch);
fclose($fp);
?>
so far only have this to load it
$xml = @simplexml_load_file('feed.xml') or die("feed not loading");
thanks