I am trying to pass some html form input through google distance matrix api. I have put them into variables and replaced the spaces with "+" signs. When I echo the variables they are perfect. When I hard code those variable values the api returns the distance, but it returns nothing when I use the variable representations.
<?php
$start = $_POST["origin"];
$end = $_POST["destination"];
$value = strtolower(str_replace(' ', '+', $start));
echo $value;
$value2 = strtolower(str_replace(' ', '+', $end));
echo $value2;
$url = 'http://maps.googleapis.com/maps/api/distancematrix/json?
origins=$value&destinations=$value2&mode=driving&language=English-
en&key=$key"';
$json = file_get_contents($url); // get the data from Google Maps API
$result = json_decode($json, true); // convert it from JSON to php array
echo $result['rows'][0]['elements'][0]['distance']['text'];
?>