str_replace 工作不正常

str_replace is not working properly

嗨,我要尝试将 x、y 位置添加到我的静态 google 地图图像位置字符串中,即

$googlemapstatic="http://maps.googleapis.com/maps/api/staticmap?center=(location)&zoom=7&size=1000x1000&markers=color%3ablue|label%3aS|11211&sensor=false&markers=size:mid|color:0x000000|label:1|(location)";

我有 x 和 y 表示它的纬度和经度

$koorX='32.323213123';
$koorY='39.3213';

并且我使用 str replace 来更改静态地图位置和其中的标记。

$newlocation=$koorX.','.$koorY;
$googlemapstatic=str_replace('location',$newlocation,$googlemapstatic);

但它显示的位置与输入的位置不同。

<img style='width:15.61cm; height:12.0cm' src=".$googlemapstatic.'>

如果我从浏览器手动写入 x,y,它会显示正确的位置。 我认为 str_replace 函数中存在一些错误,但我找不到它。

你可以试试这个:

$googlemapstatic = str_replace('(location)','('.$newlocation.')',$googlemapstatic);

使用

ini_set('display_errors','on');
error_reporting(E_ALL);

如果出现弃用类型的错误,请尝试使用 str_ireplace

$newlocation=$koorX.','.$koorY;
$googlemapstatic=str_ireplace('location',$newlocation,$googlemapstatic);