Reputation: 10757
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?
Upvotes: 0
Views: 1611
Reputation:
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.
Upvotes: 1
Reputation: 943630
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.
Upvotes: 1