如何在位置天气搜索表单“api support arabic lang”中获取阿拉伯语结果
我有用英语写的天气预报,当我输入阿拉伯城市名称时,我没有结果,当我直接用阿拉伯城市名称替换链接中的位置名时,我有我所需要的全部信息,但是当我使用搜索表单时,我有下面的代码en lang的结果。我能做什么才能得到阿朗的结果!
<meta charset="utf-8">
<main class="container text-center"
<h1 class="display-1">حالة الطقس</h1>
<form class="form-inline" method="post">
<div class="form-group mx-auto my-5">
<label class="sr-only" for="location">يرجى ادخال موقعك</label>
<input tupe="text" class="form-control" id="location" placeholder="location" name="location" size="100%">
<button class ="btn btn-primary" type="submit">ابحث الان</button>
</div>
</form>
----
$location = htmlentities($_POST['location']);
$location = str_replace(' ', '+', $location);
$geocode_url = 'https ://geocoder.api.here.com/6.2/geocode.json?searchtext='.$location.'&app_id=XXX&app_code=XXX';
$location_data = json_decode(file_get_contents($geocode_url));
发布于 2019-10-25 09:48:06
显然,这是因为动态插入的值没有正确地进行URL编码,所以修补程序需要更改。
searchtext='.$location.'至
searchtext='.urlencode($location).'当您通过将URL直接输入到浏览器地址栏来测试该URL时,浏览器通常会在必要时单独应用缺失的编码--但其他系统不一定会这样做,因此您需要自己应用它。
https://stackoverflow.com/questions/58555625
复制相似问题