0

I am trying to add 2 Strings like this:

$response = array(); $target_dir = "uploads/"; $public_key = "f1vlje6378uh6ucok8sda1exo5lmbu"; $target_dir .= $public_key."/"; $response["target_dir created"] = $target_dir; echo json_encode($response); 

"target_dir created": "uploads\/f1vlje6378uh6ucok8sda1exo5lmbu\/"

Any ideas why this "\/" appear and not just "/" ?

2
  • 3
    See: stackoverflow.com/questions/1580647/… Commented Feb 23, 2020 at 15:37
  • 1
    a backslash is used to escape the slash. There is no problem with that. If you parse the JSON back to an array, it will be in normal form, without the backslash. Commented Feb 23, 2020 at 15:41

1 Answer 1

1

It's the default behavior where it escapes the slash.

If you do not want to get the slashes to be escaped, you can do it like this:

echo json_encode($response, JSON_UNESCAPED_SLASHES); 

Here's the documentation of json_encode() and the various options you can use: https://www.php.net/manual/en/function.json-encode.php

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.