PHP: avoid backslash on json_encode

Hey! 🙂 If you are encoding your Arrays to JSON in PHP using json_encode() and the function adds backslash before your slashes, I’m gonna show you a quick fix.

This is my original code:

And the result is:
{"success":true,"message":"Please enter email\/phone number."}

See the added backslash before the slash? Ugly, right? To avoid that, simply add the JSON_UNESCAPED_SLASHES argument to your json_encode() function usage like this:

Try it!

Related Posts:

Posts that may be related to "PHP: avoid backslash on json_encode":

Catzie

An odd human being who happens to have a variety of ever-changing interests, but right now they are programming, making up silly song/rap lyrics, K-pop, drawing, creating unique dessert/drink flavors, obsessing about finding out how some things works, automation, anime, video games... Ran online dessert shops Cookies PH and Catzie's Cakery in her past life.

Leave a Reply

Your email address will not be published. Required fields are marked *