我有一个php文件,它接受来自url的JSON数据。我希望一些键和值包括在我的本地数据库中,其余的键和值上传到OpenStreetMap(OSM)的数据库中。
我想用主php文件中的GET参数调用相应的php文件。
我的脚本如下:
<?php
$url = "something";
$parts = file_get_contents($url);
$json = json_decode($parts);
//echo(sizeof($json));
$private = array("people_count");
$to_osm = array("Rent","drinking_water","Shop","communication","Energy_source","waste_management","Internet_access","emigrants","number_storey","adboard");
foreach ($json as $object) {
$get_url = "?id=";
foreach ($object as $key => $value) {
if ($key == "osmid") {
$id = $value;
$geom = "Polygon";
$get_url.=$id."&geom=".$geom;
//print_r($get_url);
}
elseif (in_array($key, $to_osm)) {
$get_url.="&".$key."=".$value;
}
}
print_r("updateOSM.php".$get_url);
}
?>
我试着加入,但没有成功。我无法重定向我的页面,因为我正在运行循环。
如有任何帮助,我们将不胜感激。
尝试这个
header('Location: updateOSM.php'.$get_url);
exit();
无论如何
header('Location: updateOSM.php'.$get_url);
这是一个合适的解决方案,因为在你点击这个语句后,你会立即转到另一个页面来制动下一次执行,所以你不需要exit()
或die()
我试过这个:
<?php
$url = "something";
$parts = file_get_contents($url);
$json = json_decode($parts);
$private = array("people_count");
$to_osm = array("Rent","drinking_water","Shop","communication","Energy_source","waste_management","Internet_access","emigrants","number_storey","adboard");
foreach ($json as $object) {
$get_url = "?id=";
foreach ($object as $key => $value) {
if ($key == "osmid") {
$id = $value;
$geom = "Polygon";
$get_url.=$id."&geom=".$geom;
//print_r($get_url);
}
elseif (in_array($key, $to_osm)) {
$get_url.="&".$key."=".$value;
}
}
header('Location: updateOSM.php'.$get_url);
}
exit();
?>
重定向后的url如下所示:
updateOSM.php?id=*******&geom=多边形&租金=否;drinking_water=公共供应&商店=没有&communication=yes&Energy_source=太阳能&waste_management=败血病库&Internet_access=是&移民=不;number_ storey=7&广告牌=是
它显示的id是我的数组$json的最后一个索引。当我在osm.org中查看该功能的更改时,我只看到最后一个功能被修改,而没有看到其他功能。
我想要的是更新OSM以获取每个数组元素,而不仅仅是最后一个进行更改。