Jump to content

Added slashes


DarkElf

Recommended Posts

I'm building a simple content managment system fo my website. The website is basically a template page which defines all the headers, footers and borders for the website and then the specific html content of each page is stored in a txt file which is added to the template using include. The CMS opens these txt files and loads their content into a textarea in which I can modify the code, then it uses fwrite to write the code back to the file when you submit it.It's very very basic and has several holes (for instance if the page you are modifying also contains a textarea the whole thing goes squewiff :)) but most of which aren't major problems and I can fix them myself. It's not intended to be super clever anyway, it simply allows me to modify the html of my pages online without having to use an ftp client to upload every little change.The problem I don't understand is that when it writes the file is adds a backslash (\) to every occurence of ". e.g. the original file contains the code <p class="main">, this is also what appears in the text area when it is loaded into it (using fgets and echo statements), however when it writes back to the file using fwrite it writes <p class=\"main\">, which obviously messes up the page! I assume that the php does this to escape the " symbol which would otherwise cause problems in the script, but why does it do it by itself without my instructing it to? and is there a way round my problem?

Link to comment
Share on other sites

You just add the line:

php_flag magic_quotes_gpc off

to the htaccess file.It's clean but it does mean that if you are moving the page to another location or server you have to ensure that you remember to update the new htaccess file (assuming magicquotes is a problem at the new location). If you use the stripslashes line its not as clean but makes the code more portable as you needn't have to worry about remembering to do this.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...