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