loading xml file from url problem
Posted: Thu Mar 13, 2008 9:06 am
my setup is this
I have a php file that displays prices, it calls another php file that gets the xml file from a URL:
pricefeed.php:
If I run this when the url is unavailable I get "file doesn't exist", but I can't figure out how to call this file without a parsing error if the file is unavailable.
The calling line:
Gives the error:
TIA
Ed
I have a php file that displays prices, it calls another php file that gets the xml file from a URL:
pricefeed.php:
Code: Select all
<?php
$fileUrl = "http://someurl.com/prices.xml";
$AgetHeaders = @get_headers($fileUrl);
if (preg_match("|200|", $AgetHeaders[0])) {
// file exists
echo"file exists";
readfile($fileUrl);
}
else
{
// file doesn't exist
echo"file doesn't exist";
return false;
}
?>
The calling line:
Code: Select all
$xml = simplexml_load_file('http://localhost/scripts/pricefeed.php');Gives the error:
If I get rid of the "file exists" echoes from the pricefeed.php file I getWarning: simplexml_load_file() [function.simplexml-load-file]: http://localhost/scripts/pricefeed.php:1: parser error : Start tag expected, '<' not found in C:\xampp\htdocs\prices.php on line 17
Any ideas?Document is empty in C:\xampp\htdocs\prices.php on line 17
TIA
Ed