Jump to content

Recommended Posts

I need to, find out how I can, have a double backslash  \\  before various characters like quotation marks.

I need this, as I use the echo keyword, to create JSON, for a website of mine.

Now, I have spent hours experimenting, and so on, and the following is what I have done.....

When I use  addslashes($a), I get one backslash each time,  when I nest one inside the other like addslashes(addslashes($a)), I get three each time.

Both times, the JSON parse operator rejected the input.

The only option that the JSON parse operator would accept is, when I had two backslashes.  That worked out perfectly fine.

At the same time, if I may ask this in this forum, I will be happy to accept any javascript solution of which you want to put forward to me here too.  I just have JSON.parse(....responseText) on that end.

Link to comment
https://forums.phpfreaks.com/topic/317176-how-to-insert-double-backslash/
Share on other sites

17 minutes ago, KangaBytes said:

I need to, find out how I can, have a double backslash  \\  before various characters like quotation marks.

Why?

$str = "The man from Del Monte, he said \"Yes!\"";
$j = json_encode($str);

echo $j . '<br>';                    //  "The man from Del Monte, he said \"Yes!\""

echo json_decode($j);                //  The man from Del Monte, he said "Yes!"

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.