我有带有html代码的php文件,当api有问题(rates.php显示错误且未显示)时,我的div显示了包含的rates.php文件中的货币汇率(它从本地国家银行Api获取汇率)率)所有站点(此php包含的代码之后)都中断了,没有渲染,我能以某种方式阻止它停止渲染吗?
<?
$client = new SoapClient('http://nbg.gov.ge/currency.wsdl');
print ("Exchange Rates: 1 USD - ");
print $client->GetCurrency('USD').'₾ |';
$client2 = new SoapClient('http://nbg.gov.ge/currency.wsdl');
print (" 1 EUR - ");
print $client2->GetCurrency('EUR').'₾';
?>
答案 0 :(得分:0)
未能实例化Soap Client会抛出异常,以便您可以尝试类似的事情
<?php
try {
$client = new SoapClient('http://nbg.gov.ge/currency.wsdl');
print ("Exchange Rates: 1 USD - ");
print $client->GetCurrency('USD').'₾ |';
print (" 1 EUR - ");
print $client->GetCurrency('EUR').'₾';
} catch (Exception $e) {
echo 'A nice message telling the user that something is wrong, try again in a little while';
//echo $e->getMessage();
}
PS您不需要2个SoapClient实例,一个实例会很好。