i load file from server:
$url = 'http://www.sample.com/test.xml';
$xml = simplexml_load_file($url);
And if servers is close i get error:
Warning: simplexml_load_file() [function.simplexml-load-file]: php_network_getaddresses: getaddrinfo failed:...
Warning: simplexml_load_file() [funct开发者_如何学JAVAion.simplexml-load-file]: I/O warning : failed to load external entity
how to check if the file is reached?
From the manual page for simplexml_load_file
Returns an object of class
SimpleXMLElement
with properties containing the data held within the XML document. On errors, it will returnFALSE
.
which means you can do
$url = 'http://www.sample.com/test.xml';
$xml = simplexml_load_file($url);
// check what was returned
if(FALSE === $xml) {
echo 'could not open file';
}
精彩评论