I am working with a 3rd party SMS supplier which they are sending me the delivery report of the SMS via URL as below:
http://www.mydomain.com/dlr.php <DeliveryReport><message id="024042313063119191" sentdate="2014/04/23 15:06:31" donedate="2014/04/23 15:06:35" status="DELIVERED" gsmerror="0" price="7.0" /></DeliveryReport>
And i am trying to read the XML data in dlr.php like below:
<?php
// read raw POST data
$postData = file_get_contents("php://input");
$dom = new DOMDocument();
$dom->loadXML($postData);
// create new XPath object for quering XML elements (nodes)
$xPath = new domxpath($dom);
// query “message” element
$reports = $xPath->query("/DeliveryReport/message");
// write out attributes of each “message” element
foreach ($reports as $node) {
echo “<br>id: “ . $node->getAttribute('id');
echo “<br>sent: “ . $node->getAttribute('sentdate');
echo “<br>done: “ . $node->getAttribute('donedate');
echo “<br>status: “ . $node->getAttribute('status');
echo “<br>gsmerrorcode: “ . $node->getAttribute('gsmerrorcode');
}
?>
I am getting this error:
Warning: DOMDocument::loadXML(): Empty string supplied as input in dlr.php
Any help how can I read the posted data correctly.
Thanks,
You can simply use this function for getting data from XML
function getFeed($feed_url)
{
$content = file_get_contents($feed_url);
$x = new SimpleXmlElement($content);
foreach($x->channel->item as $entry) : ?>
<?php
$pdate = $entry->pubDate;
$pdate = rtrim($pdate,' -500');
$pdate = explode(', ',$pdate);
?>
<div >
<a href="<?php echo $entry->link; ?>" target="_blank">
<span > <?php echo $entry->title;?></span></a> <?php echo $pdate[1]; ?>
</div>
<?php
endforeach;
}
getFeed("// Your URL");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.