小编Osm*_*man的帖子

如何通过 PHP 使用 Nominatim API 来检索经纬度?

下面是我目前使用的代码,我将地址传递给函数,Nominatim API 应该返回一个 JSON,我可以从中检索地址的纬度和经度。

function geocode($address){

    // url encode the address
    $address = urlencode($address);

    $url = 'http://nominatim.openstreetmap.org/?format=json&addressdetails=1&q={$address}&format=json&limit=1';


    // get the json response
    $resp_json = file_get_contents($url);

    // decode the json
    $resp = json_decode($resp_json, true);


        // get the important data
        $lati = $resp['lat'];
        $longi = $resp['lon'];

            // put the data in the array
            $data_arr = array();            

            array_push(
                $data_arr, 
                    $lati, 
                    $longi
                );

            return $data_arr;

}
Run Code Online (Sandbox Code Playgroud)

它的问题是我总是以内部服务器错误告终。我检查了日志,并且不断重复:

[[DATE] America/New_York] PHP Notice: Undefined index: title in [...php] on line [...]

[[DATE] America/New_York] PHP Notice: Undefined …

php json geocoding latitude-longitude nominatim

3
推荐指数
1
解决办法
7869
查看次数

如何用 HTML 标签替换包含字符串的文本?

我正在尝试找出如何用 HTML 标签替换页面上与某个短语匹配的任何文本实例 - 内容应保持不变。

bold("Hello")
Run Code Online (Sandbox Code Playgroud)

上面的代码应该替换为:

<b>Hello</b>
Run Code Online (Sandbox Code Playgroud)

这是我当前正在使用的代码:

node.data = node.data.replace('bold("','<b>');
node.data = node.data.replace('")','</b>');
Run Code Online (Sandbox Code Playgroud)

这样做的问题是,<b>它不是创建标签,而是将<和转换>为它们的 HTML 实体 - << >

")此外,用替换所有实例似乎不切实际</b>

实现这一目标的最佳方法是什么?

我将不胜感激任何帮助,谢谢!

html javascript replace html-entities

3
推荐指数
1
解决办法
2万
查看次数