简体   繁体   English

str_replace 无法正常工作

[英]str_replace is not working properly

Hi im gonna trying to add x,y location to my static google maps image location string that is嗨,我要尝试将 x,y 位置添加到我的静态谷歌地图图像位置字符串中

$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)";

and i have x and y for its latitude and longitude我有 x 和 y 的纬度和经度

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

and im using str replace for changing static maps location and marker inside it.我使用 str replace 来更改静态地图位置和其中的标记。

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

but it shows me different location than input.但它显示了与输入不同的位置。

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

If i write that x,y manually from browser, it show correct location.如果我从浏览器手动写入 x,y,它会显示正确的位置。 I assume that there is some mistake in str_replace function but i couldn't find it.我认为 str_replace 函数中有一些错误,但我找不到它。

你可以试试这个:

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

use

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

if deprecated kind of error then try to use str_ireplace如果不推荐使用的错误类型,则尝试使用 str_ireplace

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM