PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I need to make a page so that a client can easily edit a large amount of text online. I am currently using a textarea that includes() the .txt file with the necessary text. The client can make changes, hit submit, and the form sends the value to a php file that writes the new edited text over the old text. The only problems is that any quotes get slashes added to them when I write to the file. Do I need to use addslashes(), stripslashes(), or something like that?
It depends on what you want to do with the data in the file. If you wanted to display it in HTML then you would stripslashes() to clean up the test and htmlentities() to prevent cross-site scripting attacks. If you were transfering the file to a database then you use the database's escaping function.
this would write clean text to the file. (the only change i've made here is that the variable $text is initialised to an empty string if the POST var textarea is not set.)
The slashes are probably being added because you have the magic_quotes_gpc directive turned on in php.ini. You can check that by calling get_magic_quotes_gpc():