I am having difficulty formatting the XML response from a php curl xml api for infobip. My code below loops sms to mobile numbers. But i want to format the XML responses to show the messages successfully sent and those that were not successful using a conditional if else statement.
while ($row = mysql_fetch_array($result))
{
// XML-formatted data
$xmlString='
<SMS> <authentication> <username>'.$user.'</username> <password>'.$pass.'</password> </authentication> <message> <sender>'.$sender.'</sender> <text>'.$message.'</text> <recipients> <gsm>'.$mobileno.'</gsm>
//<gsm>'.$mobileno1.'</gsm> </recipients> </message> </SMS>';
$fields = "XML=" . urlencode($xmlString);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $postUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$response = curl_exec($ch);
curl_close($ch);
if($response->status == '0') {
echo "message successfully delivered to ".$mobileno. "<br>" ;
}else{
echo "error sending message to ".$mobileno."<br>" ;
}
}
The problem i have is being able to set or parse the XML response for to get the <status> XML tags. Currently this how the XML responses outputs the results without formatting.
<?xml version="1.0" encoding="UTF-8"?> <results> <result><status>1</status><messageid></messageid><destination>23421</destination></result> </results><?xml version="1.0" encoding="UTF-8"?> <results> <result><status>0</status><messageid></messageid><destination>23412</destination></result> </results><?xml version="1.0" encoding="UTF-8"?> <results> <result><status>0</status><messageid></messageid><destination>23444</destination></result> </results>
I would appreciate to get this solved