I have some html code I want to store in a database. I need a way to encode it in php so all the special characters don’t break the db INSERT (the html can include all sorts of spec chars) and then a way to unencode that at the other end in javascript once i’ve passed it via JSON so that the html is rendered correctly.
IS there any way I can do this?
Since you are using PHP:
For the database, use PDO: http://bobby-tables.com/php.html
And for the JSON, use the json methods: http://php.net/json
These handle all the escaping for you.