In my PHP project, I have an url path string returned like:
{ "data": { "image": "https://uploads-ssl.webflow.com/5f6a30b165eb44156b3bc6ca_N%20GRAPH%20SETTINGS.png", "url": "https://www.uhub.io/" } }
What I would like to accomplish is for this two paths to be without and
%
..
How can I format them?
I know this question is already answer but I can not find right PHP fucntion for it.
Code:
$encodeData = json_encode($metaData); return json_decode($encodeData, true);
and the problem persists.
Advertisement
Answer
Working Solution:
The PHP Function stripcslashes() does what you need: Removes the escaping character where it’s not needed.
The %.. characters are part of URL Encoding, so don’t remove them.
Here is a working solution how to remove the from your object:
<?php $data = [ 'image' => "https://uploads-ssl.webflow.com/5f6a30b165eb44156b3bc6ca_N%20GRAPH%20SETTINGS.png", 'url' => "https://www.uhub.io/" ]; foreach($data as $key => $value) { $data[$key] = stripcslashes($value); } print_r($data);
Old answer:
This is a JSON String and the backslashes are part of JSON formatting.
Remove it by decoding it:
$data = '{ "data": { "image": "https://uploads-ssl.webflow.com/5f6a30b165eb44156b3bc6ca_N%20GRAPH%20SETTINGS.png", "url": "https://www.uhub.io/" } }'; $rawData = json_decode($data, true);
$rawData
is now:
Array ( [data] => Array ( [image] => https://uploads-ssl.webflow.com/5f6a30b165eb44156b3bc6ca_N%20GRAPH%20SETTINGS.png [url] => https://www.uhub.io/ ) )