eyrique Posted February 9, 2009 Share Posted February 9, 2009 hi, my application is to receive an xml posted by others, for example: $xml = "<?xml version='1.0' encoding='utf-8'?> <address> <street>Lot 11, Happy Street</street> <state>Florida</state> <country>USA</country> </address> "; $ch = curl_init("http://localhost/address/index.php"); curl_setopt($ch, CURLOPT_TIMEOUT, 20); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, array( 'xml' => $xml, )); $response = curl_exec($ch); curl_close($ch); and i received it to process. so i use $xml_array = simplexml_load_string($_POST['xml']); but the problem is it shows this errors: Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : String not started expecting ' or " in C:\AppSer\process.php on line 14 Warning: simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"utf-8\"?> in C:\AppSer\process.php on line 14 Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\AppSer\.php on line 14 Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Malformed declaration expecting version in C:\AppSer\.php on line 14 Warning: simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"utf-8\"?> in C:\AppSer\process.php on line 14 Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\AppSer\process.php on line 14 Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Blank needed here in C:\AppSer\process.php on line 14 Warning: simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"utf-8\"?> in C:\AppSer\process.php on line 14 Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\AppSer\process.php on line 14 Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : parsing XML declaration: '?>' expected in C:\AppSer\process.php on line 14 Warning: simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"utf-8\"?> in C:\AppSer\process.php on line 14 Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\AppSer\process.php on line 14 but then i tried to print_r($_POST['xml']) and i got this result: <?xml version=\'1.0\' encoding=\'utf-8\'?> <address> <street>Lot 11, Happy Street</street> <state>Florida</state> <country>USA</country> </address> if seems like the server automatically convert the '1.0' into \'1.0\' is this the cause that make the simplexml_load_string function work wrongly? is there any way to solve this? thanks alot Link to comment https://forums.phpfreaks.com/topic/144455-solved-posting-a-xml-variable-using-simplexml_load_string/ Share on other sites More sharing options...
RichardRotterdam Posted February 9, 2009 Share Posted February 9, 2009 this might help stripslashes Link to comment https://forums.phpfreaks.com/topic/144455-solved-posting-a-xml-variable-using-simplexml_load_string/#findComment-758004 Share on other sites More sharing options...
eyrique Posted February 9, 2009 Author Share Posted February 9, 2009 thanks a lot... it works! Link to comment https://forums.phpfreaks.com/topic/144455-solved-posting-a-xml-variable-using-simplexml_load_string/#findComment-758007 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.