L
L
leni_m2017-07-14 14:23:55
PHP
leni_m, 2017-07-14 14:23:55

How to check for xml file upload?

I load the xml file of currencies using

$xml = simplexml_load_file('url из интернета');
$usd = (string)$xml->Valute[10]->Value;
$eur = (string)$xml->Valute[11]->Value;

But when there is no internet connection, an error is displayed
Warning: simplexml_load_file(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /home/leni_m/www/lk.local/public_html/views/template/header.php on line 2

Warning: simplexml_load_file(url из интернета): failed to open stream: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /home/leni_m/www/lk.local/public_html/views/template/header.php on line 2

Warning: simplexml_load_file(): I/O warning : failed to load external entity "url из интернета" in /home/leni_m/www/lk.local/public_html/views/template/header.php on line 2

How can you avoid throwing an error?
PS The very first line for some reason returns an error, not false
$xml = simplexml_load_file('url из интернета');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeniy Samoilenko, 2017-07-14
@leni_m

Try {
// do something
} catch(\Exception $e) {
// catch something
}
Try catch

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question