$usernameP$proNmbr";
foreach ( explode(',',$poNmbrs) as $poNmbr) $xmlRequest .= "$poNmbr";
$xmlRequest .= "3213A789283Alan Shipley1234 NE MainPortlandOR97202503.450.6055vonderluft.andrew@Con-way.com$consigneeNum503.450.6800vonderluft.andrew@Con-way.com44667widget-arms775N";
foreach ( explode(',',$accessorials) as $acc) $xmlRequest .= "$acc";
$xmlRequest .= "TEST TEST TEST".$today."4:00 pm7:00 pmFrankFranklin Arms(333)444-4321
";
//Convert characters to proper format for HTTP POST
$xmlRequest = urlencode($xmlRequest);
// open synchronous connection to Con-way servlet and set options
$urlConn = curl_init ($requestUrl);
curl_setopt ($urlConn, CURLOPT_POST, 1);
curl_setopt ($urlConn, CURLOPT_SSL_VERIFYPEER, false); // May be needed for SSL behind a firewall
curl_setopt ($urlConn, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded"));
curl_setopt ($urlConn, CURLOPT_USERPWD, $username.":".$password);
curl_setopt ($urlConn, CURLOPT_POSTFIELDS, "$requestType=$xmlRequest");
// Get the XML Response
ob_start(); // prevent the buffer from being displayed
curl_exec($urlConn);
$xmlResponse = ob_get_contents();
ob_end_clean();
curl_close($urlConn); // close the connection
// Parse the XML Response
$parser= xml_parser_create();
xml_parse_into_struct($parser,$xmlResponse,$xmlVals);
xml_parser_free($parser);
// This function will return an array of the values of an element
// given the $vals and $index arrays, and the element name
function getElementValue($xmlVals, $elName) {
$elValue = null;
foreach ($xmlVals as $arrkey => $arrvalue) {
foreach ($arrvalue as $key => $value) {
if ($value==strtoupper($elName)){
$elValue[] = $arrvalue['value'];
}
}
}
return $elValue;
}
// Build the HTML page
echo "
Sample PHP for Con-way XML $title>
Sample PHP Con-way XML $title
";
// Extract your element values from the XML Response
$elCount = count(getElementValue($xmlVals, $myElements[0])); // total occurrences
// The outer loop iterates the total number of occurrences of your first element
for ($i=0; $i < $elCount; $i++) {
// The inner loop iterates all of your elements, for each occurrence of the first
foreach ($myElements as $myEl) {
$myVals = getElementValue($xmlVals, $myEl);
echo "Value of <$myEl> is: $myVals[$i] ";;
}
echo ' ';
}
echo "Here is the dump of the XML output for $title: " .
"$xmlResponse
" .
"And here it is displayed as a formatted array: ";
print_r($xmlVals);
echo
"" .
"";
?>