Skip to content
Advertisement

WordPress json_encode and json_decode with quotes, slashes, emojis

I have a data array such as

JavaScript

Now, the title/options can have special characters such as “quotes” and also ‘single ones’, along with maybe/slashes as well or emojis.

Unfortunately, upon adding these to the data and encoding, I can’t decode it. Well, rather, WordPress just returns empty.

JavaScript

Above, $retrieved is:

JavaScript

But $decoded ends up empty/null

I’ve tried various sorts of add/stipslashes and also htmlspecialentities to no avail

Advertisement

Answer

So, this ended up being the proper way to clean the string before json_encode

JavaScript

Seems crazy, but it works with quotes, double quotes, slashes, and emojis.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement