Skip to content

Instantly share code, notes, and snippets.

@up1
Created January 12, 2010 10:05
Show Gist options
  • Save up1/275078 to your computer and use it in GitHub Desktop.
Save up1/275078 to your computer and use it in GitHub Desktop.
function responseXML($url ='',$post_data ='', $parse=false){
$ch = curl_init(); //initiate the curl session
curl_setopt($ch, CURLOPT_URL, $url); //set to url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // tell curl to return data ina variable
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); // post the xml
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // set timeout in seconds
$xmlResponse = curl_exec ($ch);
if (curl_errno($ch)) {
print curl_error($ch);
} else {
curl_close($ch);
}
if(!$parse){
return $xmlResponse;
}else {
$aData = array();
if(trim($xmlResponse)!=""){
$dom = new DOMDocument;
$dom->loadXML($xmlResponse);
$this->readXml($dom , $aData);
}
return $aData;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment