I am invoking PHP cURL method on a server and the response is XML type. cURL is saving the output (after removing the tags) in a scalar type variable. Is there a way to store it in an object/hash/array so that it's easy to parse?
Just add header('Content-type: application/xml'); before your echo of the XML response and you will see an XML page.
To send XML to the server using Curl, you need to pass the XML data to Curl with the -d command line option and specify the data type in the body of the POST message using the -H "Content-Type: application/xml" command-line option.
To post XML using Curl, you need to pass XML data to Curl with the -d command line parameter and specify the data type in the body of the POST request message using the -H Content-Type: application/xml command line parameter.
<?php function download_page($path){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$path); curl_setopt($ch, CURLOPT_FAILONERROR,1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_TIMEOUT, 15); $retValue = curl_exec($ch); curl_close($ch); return $retValue; } $sXML = download_page('http://alanstorm.com/atom'); $oXML = new SimpleXMLElement($sXML); foreach($oXML->entry as $oEntry){ echo $oEntry->title . "\n"; }
Just add header('Content-type: application/xml');
before your echo of the XML response and you will see an XML page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With