1

I am having problems with the following:

$xml4 = simplexml_load_file($fulllink4, 'SimpleXMLElement', LIBXML_NOWARNING);

$fulllink4 is dynamically generated. Sometimes the URL that is generated inside $fulllink4 is malformed and I get an error as follows :

Warning: simplexml_load_file(http://xxxx.com): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in D:\xxxx.php on line 90

I had read that by adding the ", 'SimpleXMLElement', LIBXML_NOWARNING);" part to the line that it should suppress any errors, but it does not.

Does anyone know how I can completely suppress all errors generated by that line?

Thank you in advance.

4

2 回答 2

1

可以使用 来抑制错误@,但被高度认为是一个坏主意。

if($xml4 = @simplexml_load_file($fulllink4, 'SimpleXMLElement', LIBXML_NOWARNING)){
    // all other references to $xml4
}
于 2013-10-16T18:14:59.250 回答
1

尝试这个:

$xml4 = simplexml_load_file($fulllink4, 'SimpleXMLElement', LIBXML_NOWARNING & LIBXML_NOERROR);

也可能(可能)您看到的错误/警告早在 XML 被实际解析之前就已生成(即,在 fetch 阶段,这很可能通过 PHP 的标准流包装器发生,即 file_get_contents() 和喜欢 )

你可能应该看看这个:http ://www.php.net/manual/en/simplexml.examples-errors.php

于 2013-10-16T18:09:27.940 回答