Amir Rachman Amir Rachman - 6 months ago 13
JSON Question

Handling Space url in json

I've url like this for the json format.

http://abcde.com/api.php?CMD=TRACKVEHICLE&APIKEY=1234&TERMINAL=358899052470419&GPSSTART=13-05-2016 2000:34:00&GPSEND=13-05-2016 2014:34:00


when i passed to url in the browser there is an extra '%' string like below

http://abcde.com/api.php?CMD=TRACKVEHICLE&APIKEY=1234&TERMINAL=358899052470419&GPSSTART=13-05-2016%2000:34:00&GPSEND=13-05-2016%2014:34:00


how to handle that % ?, how to convert to UTF-8 my script can read the json format, just like i paste on the browser.

public function getMapLine() {

$superspring_url="http://abcde.com/api.php?CMD=TRACKVEHICLE&APIKEY=1234&TERMINAL=358899052470419&GPSSTART=13-05-2016 2000:34:00&GPSEND=13-05-2016 2014:34:00";

$curl = curl_init($superspring_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
//execute the session
$curl_response = curl_exec($curl);
//finish off the session
curl_close($curl);

$decoded = json_decode($curl_response,TRUE);


var_dump($curl_response);
}


i use that above script to dump but this one is the below result because of the '%' string.

string(14) "Query failed! "


but when i try to use that % on my php script it shown the url.

Answer

Add the below code above $curl = curl_init($superspring_url); :

$superspring_url = str_replace (' ', '%20', $superspring_url);