Google距離行列APIを介してHTMLフォーム入力を渡そうとしています。それらを変数に入れ、スペースを「+」記号に置き換えました。変数をエコーすると、それらは完璧です。これらの変数値をハードコーディングすると、API は距離を返しますが、変数表現を使用すると何も返しません。
<?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'];
?>