0
を使用しているURLの文字を置換する
Google Places APIを使用しています... &(アンパサンド)の場所を保存しようとしています。変数をエンコードしているようです。たとえば、ビジネス名はDave & Bustersと呼ばれていますが、パラメータとして予約されているので、リクエストURLのURLに&を使用できます。これらの2つの機能を使用して見つかった場合は&を置き換えようとしました。たぶん私は間違って使用して..&
$name = 'Dave & Busters';
if (strpos($name, '&') !== false) {
//& SIGN FOUND
//WONT WORK FOR URL NEED TO REPLACE
$name = str_replace('&', 'and', $string);
}
$name = urlencode($name);
$url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=$lat,$long&radius=10&type=restaurant&keyword=$name&key=myKey";
EDIT *私はこれを取得します。 Dave +のみ表示
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=40.7455483,-73.5951152&radius=10&type=restaurant&keyword=Dave+&key=AIzaSyD4rcVpAgnP650-DCeL2L4zTnPSo4d81vk
が、それは() ''でurlencode前のものを交換するデイブ+のみ – Carlitos
@Carlitosストップまで出力し続ける:
いっそのこと、ちょうど
http_build_query()
を使用しています。 – Brad私もそれをやってみました。パラメータがdave&bustersアンパサンドと混同されているので、私は何の応答も得ません $ url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=$lat,$long&radius = 10&type =レストラン&キーワード= $ name&key = myKey "; – Carlitos