PHP does not replace a character in a string

0

I'm doing a query with CURL in PHP


$handler = curl_init("https://doffice.dexcar.de/api/AdvisorProfile/15ef1274-6ff5-4b3c-87bd-02f9f103fdb9");  
curl_setopt($handler, CURLOPT_SSL_VERIFYPEER, false);  
$response = curl_exec($handler);  
curl_close($handler);  
$response = substr($response, 0, -1);
$response = str_replace("\"", "'", $response);
print_r(json_decode($response)); 

That query returns a json which I convert to an PHP array with json_decode() , but it does not convert it because it returns the json in this way

[{"Id":"15ef1274-6ff5-4b3c-87bd-02f9f103fdb9","Name":"Livio PEDRON","Nickname":"THE_BOSS","Photo":null,"City":"RIVOLI","Address":{"Street":"via Ivrea, 14/E","Zip":"10098","Country":{"Code":"IT","Name":"Italy"}},"Level":"Advisor","Email":"[email protected]","Phone":"+39 335 5206976","Rating":0.0,"Zone":"TORINO"}]

The idea is to convert the double quote ( " ) into a single quote ( ' ) but for some reason, it does not.

    
asked by Anthony Medina 17.05.2018 в 19:21
source

2 answers

0

I have already solved it, replaced all my PHP code with the following

$content = json_decode(file_get_contents("https://doffice.dexcar.de/api/AdvisorProfile/15ef1274-6ff5-4b3c-87bd-02f9f103fdb9"), true);

print_r($content);
    
answered by 17.05.2018 в 19:51
0

You are missing a header at CURL to indicate that the request returns something to you.

  

CURLOPT_RETURNTRANSFER

     

TRUE to return the result of the transfer as a string of the   value of curl_exec() instead of showing it directly.

Then it would be as follows and without replacing anything in the string.

$url = "https://doffice.dexcar.de/api/AdvisorProfile/15ef1274-6ff5-4b3c-87bd-02f9f103fdb9";
$handler = curl_init($url);
curl_setopt($handler, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handler, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($handler);
curl_close($handler);

print_r(json_decode($response));
    
answered by 17.05.2018 в 19:51