stuart7398 Posted April 3, 2008 Share Posted April 3, 2008 hi. can anyone briefly tell me why we use 'stripslashes' and when they are to be used. thanks. stuart. Quote Link to comment Share on other sites More sharing options...
almightyegg Posted April 3, 2008 Share Posted April 3, 2008 <?php $str = "Is your name O\'reilly?"; // Outputs: Is your name O'reilly? echo stripslashes($str); ?> Quote Link to comment Share on other sites More sharing options...
unsider Posted April 3, 2008 Share Posted April 3, 2008 Further explanation http://us3.php.net/stripslashes Quote Link to comment Share on other sites More sharing options...
xnowandtheworldx Posted April 3, 2008 Share Posted April 3, 2008 And for the use of it..say...when you have someone submit a comment and you use mysql_real_escape_string...so that there is no sql injection..when you want to display the comment say the comment was.."Hello, i'm matt" when you submit the comment, when it is inserted into the database it will be "Hello, i\'m matt" so when you display the comments you want you can use stripslashes() so that it appears as "Hello, i'm matt". Hope this helps you some. Quote Link to comment Share on other sites More sharing options...
stuffradio Posted April 3, 2008 Share Posted April 3, 2008 Basically emphasizing on what the previous poster said... you will want to sanitize your mysql queries. When someone posts some data you're entering, you will usually want to add slashes to it just in case they try injecting it. So when you are displaying the data of what was inserted in to the query, you'll strip the slashes so it doesn't show things like "Hi, I\'m a PHP coder." Instead it'd show "Hi, I'm a PHP coder." Quote Link to comment Share on other sites More sharing options...
trq Posted April 4, 2008 Share Posted April 4, 2008 When you escape data using slashes (addslashes, mysql_real_escape_string etc etc) and then store it within the database the slashes do not stay with the data, the slashes only escape bad characters so you can get the data into the database. The only time you really need to use stripslashes is when you have escaped a string for whatever reason then would like to display it. Quote Link to comment Share on other sites More sharing options...
stuart7398 Posted April 4, 2008 Author Share Posted April 4, 2008 thanks to everyone for that lesson in stripslashes. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.