KangaBytes Posted August 10, 2023 Share Posted August 10, 2023 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. Quote Link to comment https://forums.phpfreaks.com/topic/317176-how-to-insert-double-backslash/ Share on other sites More sharing options...
Barand Posted August 10, 2023 Share Posted August 10, 2023 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!" Quote Link to comment https://forums.phpfreaks.com/topic/317176-how-to-insert-double-backslash/#findComment-1611031 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.