I'm having issues escaping/stripping strings with PHP/MySQL - there always seems to be redundant slashes.
Let's take the following string as an example:
<span style="text-decoration:underline;">underline</span>
When adding a string to the database, I'm escaping it with mysql_real_escape_string()
and the following gets stored in the database (EDIT: checked this by querying the database directly with mysql app):
<span style=\\\"text-decoration:underline;\\\">underline</span>
When reading back out of the database, I'm passing the string through stripslashes()
and the following is returned:
<span style=\"text-decoration:underline;\">underline</span>
Since the quotes are still escaped, it breaks the html and the text is not underlined.
- Why is
mysql_real_escape_string()
adding three slashes, andstripslashes()
removing two slashes? I would expect them both to add/remove one slash. - How can I prevent this from happening?
- Am I approaching this the correct way?