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, and stripslashes()
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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…