PHP - What is the differences btw addslashes, stripslashes etc

Asked By Olusegun A. on 14-Apr-11 11:15 AM

Hello there, pls i need to know the differences between the followings and if they can be used interchangeably.


I have read many articles on the above that are complicating. One of them says you use addslashes to insert into database and stripslashes to retrieve from database. But whenever i use addslashes for my form, after submiting the form, any text that has special characters like ' or " will display 3 backslashes before the character. if i use mysql_real_escape_string or mysql_escape_string, the form will return \r\n in place of the character. but if i use stripslashes it will return every special character the normal way without any problem. so which is the best?
Reena Jain replied to Olusegun A. on 18-Apr-11 02:23 AM

The difference between addslashes() and mysql_real_escape_string() is that mysql_real_escape_string() escapes all characters harmful to a mysql query (such as line feeds, carriage returns, quotes, and a number of other assorted special
characters), while addslashes() only escapes quotes (both single and double), backslashes, and the NULL byte.

here is a link with eg on this

Hope this will help you