将PHP变量传递给URL

时间:2018-04-10 02:25:38

标签: php google-maps

我有代码:

echo '<iframe width="600" height="450" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/place?q=266%20Orms%20St%20Providence%20RI&key=mykey"  allowfullscreen> </iframe>' ;

我想在 q = 之后将变量$ street传递到网址,例如:

src="https://www.google.com/maps/embed/v1/place?q=$street&key=mykey

地图正在显示,但$ street的实际街道未被识别。此外,我如何传递多于1个变量?我尝试过$ street和$ city,不成功:

src="https://www.google.com/maps/embed/v1/place?q=$street+city&key=mykey

2 个答案:

答案 0 :(得分:2)

您使用单引号,因此需要进行连接:

echo '<iframe width="600" height="450" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/place?q=' . urlencode($street) . '"  allowfullscreen> </iframe>';

答案 1 :(得分:0)

你也可以试试这个。

echo '<iframe width="600" height="450" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/place?q='.$street.'"  allowfullscreen> </iframe>';