Skip to content

Instantly share code, notes, and snippets.

@johnschimmel
Created November 7, 2011 18:52
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save johnschimmel/1345805 to your computer and use it in GitHub Desktop.
Save johnschimmel/1345805 to your computer and use it in GitHub Desktop.
PHP SOAP request using CURL to retrieve In The Life Station listings
<?php
function getListingsViaSoap($zipcode) {
$url = "http://www.tracmedia.com/lol/LOLService.asmx";
$soap_request = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<InTheLife xmlns="http://tracmedia.org/">
<zipCode>'.$zipcode.'</zipCode>
</InTheLife>
</soap:Body>
</soap:Envelope>';
$header = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"http://tracmedia.org/InTheLife\"",
"Content-length: ".strlen($soap_request),
);
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "http://www.tracmedia.com/lol/LOLService.asmx" );
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $soap_request);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($soap_do);
$airings = array();
if($result === false) {
$err = 'Curl error: ' . curl_error($soap_do);
curl_close($soap_do);
print $err;
} else {
curl_close($soap_do);
$content = value_in("InTheLifeResult",$result);
$contentXML = html_entity_decode($content);
$xml = simplexml_load_string($contentXML);
foreach($xml->carriage[0] as $airing) {
$tmp['station'] = strval($airing->station);
$tmp['date'] = strval($airing->date);
$tmp['time'] = strval($airing->time);
$tmp['timezone'] = strval($airing->timezone);
$tmp['episodenum'] = strval($airing->episodenum);
$tmp['episodetitle'] = strval($airing->episodetitle);
$airings[] = $tmp;
}
}
return $airings;
}
function value_in($element_name, $xml, $content_only = true) {
if ($xml == false) {
return false;
}
$found = preg_match('#<'.$element_name.'(?:\s+[^>]+)?>(.*?)'.
'</'.$element_name.'>#s', $xml, $matches);
if ($found != false) {
if ($content_only) {
return $matches[1]; //ignore the enclosing tags
} else {
return $matches[0]; //return the full pattern match
}
}
// No match found: return false.
return false;
}
/*************************************/
/* GET LISTINGS FOR 10011 zipcode */
/*************************************/
$zipcode = 10011;
print_r( getListingsViaSoap($zipcode) );
/*************************************/
?>
@reemaRaven
Copy link

What does InTheLifeResult mean in your parser? There is no such string when I hit and get a response.

@bishwa-gloify
Copy link

From where I will get "SOAPAction". Please confirm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment