php - XML Parsing/division issue -
i messing below code, , can not seem work correctly... gather of code working fine, bar division $distance1 variable.
<?php $start = 'ec1v 0es'; $end = 'ec4r 3tn'; $url = 'http://maps.googleapis.com/maps/api/directions/xml?origin='.$start.'&destination='.$end.'&sensor=false'; $xml = simplexml_load_file($url); $distance = $xml->route->leg->distance->text; $distance1 = $distance/1.609; // divided 1.609 convert km miles echo $distance; echo '<br />'; echo $distance1; ?>
does 1 have ideas ever causing this? have tested online , taken googleapis url (http://maps.googleapis.com/maps/api/directions/xml?origin=ec1v+0es&destination=ec4r+3tn&sensor=false) , seems if code pulling correct values, isn't dividing or something... ahh confused , bit of noob go nicely please :)
you should cast $distance float
$start = 'ec1v 0es'; $end = 'ec4r 3tn'; $url = 'http://maps.googleapis.com/maps/api/directions/xml?origin='.$start.'&destination='.$end.'&sensor=false'; $xml = simplexml_load_file($url); $distance = (float) $xml->route->leg->distance->text; $distance1 = $distance/1.609; // divided 1.609 convert km miles echo $distance; echo '<br />'; echo $distance1; // 4.4<br />2.7346177750155
Comments
Post a Comment