Forum Moderators: open

Message Too Old, No Replies

XML file not loading?

         

eK3eKyToPa

8:10 pm on Jan 25, 2008 (gmt 0)

10+ Year Member



This lines loads the xml file from the url, but if file is unreachable it shows a lot of errors
**********************
$url = 'http://example.com/xml';
$file = file_get_contents($url) ;
$xml = new SimpleXMLElement($file);
**********************
how can be shown simple text message if file is unreachable?

[edited by: volatilegx at 6:26 am (utc) on Jan. 26, 2008]
[edit reason] examplified [/edit]

volatilegx

6:30 am on Jan 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe...

$url = 'http://example.com/xml';
$file = file_get_contents($url);
if ($file)
$xml = new SimpleXMLElement($file);
else
echo "Could not access $url";