简体   繁体   中英

Curl not working in one server, but OK in all others

below code is not working on one server, but working fine in others. I am getting this error:

Warning: simplexml_load_string(): Entity: line 1: parser error : Opening and ending tag mismatch: HR line 1 and body in testchecker.php on line 11
Warning: simplexml_load_string(): dden.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/5.5.20</h3></body> in testchecker.php on line 11
Warning: simplexml_load_string(): ^ in testchecker.php on line 11
Warning: simplexml_load_string(): Entity: line 1: parser error : Opening and ending tag mismatch: HR line 1 and html in testchecker.php on line 11
Warning: simplexml_load_string(): Entity: line 1: parser error : Premature end of data in tag body line 1 in testchecker.php on line 11
Warning: simplexml_load_string(): Entity: line 1: parser error : Premature end of data in tag html line 1 in testchecker.php on line 11
Warning: Invalid argument supplied for foreach() in testchecker.php on line 12


    <?php
set_time_limit(0);

$url="http://test";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);  
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$data = curl_exec($ch); 
curl_close($ch);
$xml = simplexml_load_string($data);
foreach($xml->User as $child){
    echo $child->Id."<br/>";        
}
?>

I dont understand why this error is getting, because in local and other servers its working fine. On dreamhost, its not. Can anybody help me in this.

The error message already tells you, what is wrong

 Warning: simplexml_load_string(): Entity: line 1: parser error : Opening and ending tag mismatch: HR line 1 and body in testchecker.php on line 11 Warning: simplexml_load_string(): dden.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/5.5.20</h3></body> in testchecker.php on line 11 

XML requires all tags be closed, while with HTML, you can omit the closing tag occasionally.

In this case, you have a <hr> tag without a corresponding closing tag. This is perfectly valid in HTML. However, it is not well-formed XML, which is required by simplexml_load_string

Description
Takes a well-formed XML string and returns it as an object.

I have fixed the issue. The ip was blocked, so forbidden message was getting, instead of xml. Unblocking the ip fixed everything.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM