Page 1 of 1

addslashes and stripslashes

Posted: Tue Apr 01, 2003 9:59 am
by CrazyJimmy
Hello,

I have done some limited php coding and have never used either of these functions, but I see some scripts that use them all the time. All my code works and querys etc.

Can someone explain the uses of them?(other than the obvious ;) )

Is it one of those good practice things?

Thanks

Posted: Tue Apr 01, 2003 10:17 am
by Rob the R
It is one of those good practice things because there are times when you need it. The addslashes() function will insert the backslash character ("\") where it is needed in a string to be able to safely insert that value in the database. This is to make sure you could insert, say, a user comment into a database like
So I'm like, "No way!" and he's all like "Tru dat."
If you try and insert such a string into a database, it will have a hard time dealing with the quotes. Passing that string through the addslashes() function before you insert it into your database will make sure the quotes are handled correctly.

When you read the value from the database, you will need to use the stripslashes() function to restore the string back to its original form before writing it to the browser.

Posted: Tue Apr 01, 2003 1:31 pm
by CrazyJimmy
Thanks, that makes perfect sense