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.
Regarding "not breaking the db INSERT," this should be a completely moot point. You should either be appropriately escaping all user-provided data (eg. mysqli_real_escape_string ) or using binding .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.