Convert JSON value to PHP string -
need value "distance" "text" google maps api, , convert php string.
for example, https://maps.googleapis.com/maps/api/distancematrix/json?origins=tn222af&destinations=tn225dj&mode=bicycling&language=gb-fr&sensor=false&units=imperial gives us:
{ "destination_addresses" : [ "new town, uckfield, east sussex tn22 5dj, uk" ], "origin_addresses" : [ "maresfield, east sussex tn22 2af, uk" ], "rows" : [ { "elements" : [ { "distance" : { "text" : "3.0 mi", "value" : 4855 }, "duration" : { "text" : "22 mins", "value" : 1311 }, "status" : "ok" } ] } ], "status" : "ok" }
how value "3.0 mi" changed php variable json feed?
many thanks!
$json = <<<end_of_json { "destination_addresses" : [ "new town, uckfield, east sussex tn22 5dj, uk" ], "origin_addresses" : [ "maresfield, east sussex tn22 2af, uk" ], "rows" : [ { "elements" : [ { "distance" : { "text" : "3.0 mi", "value" : 4855 }, "duration" : { "text" : "22 mins", "value" : 1311 }, "status" : "ok" } ] } ], "status" : "ok" } end_of_json; $arr = (json_decode($json, true)); echo $arr["rows"][0]["elements"][0]["distance"]["text"]; --output:-- 3.0 mi
Comments
Post a Comment