Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > php adding slashes?

php adding slashes?
Thread Tools
Mac Enthusiast
Join Date: Nov 2001
Location: Washington, DC 20009
Status: Offline
Reply With Quote
Feb 4, 2003, 08:17 PM
 
I use PHP to add news entries and allow others to post comments on my website. The visitors can enter text in to a form and submit it for addition to a page. The problem I've found is that when I write the information to the file, single and double quotes are automatically escaped and I'm not sure how to prevent it from doing so. There is no reason for the quotes to be escaped. I'm using fwrite to write the string to a file handle. How do I stop PHP from automatically adding the \'s???
Just my $.02 :-)
Ti Powerbook 1Ghz w/ Superdrive ......and lovin' it! :)
     
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Feb 4, 2003, 10:04 PM
 
Originally posted by milf:
I use PHP to add news entries and allow others to post comments on my website. The visitors can enter text in to a form and submit it for addition to a page. The problem I've found is that when I write the information to the file, single and double quotes are automatically escaped and I'm not sure how to prevent it from doing so. There is no reason for the quotes to be escaped. I'm using fwrite to write the string to a file handle. How do I stop PHP from automatically adding the \'s???
$string = stripslashes($string);
Computer thez nohhh...
     
milf  (op)
Mac Enthusiast
Join Date: Nov 2001
Location: Washington, DC 20009
Status: Offline
Reply With Quote
Feb 4, 2003, 10:44 PM
 
Where do the slashes come from in the first place though? Are they automatically added by php? And if so, when, why, and how?
Just my $.02 :-)
Ti Powerbook 1Ghz w/ Superdrive ......and lovin' it! :)
     
milf  (op)
Mac Enthusiast
Join Date: Nov 2001
Location: Washington, DC 20009
Status: Offline
Reply With Quote
Feb 5, 2003, 08:06 AM
 
Okay, I did a little more research and finally found my answer. PHP auto adding slashes is a feature built in to the language. It automatically adds slashes to data submitted as HTML form data or cookies. That, to me, is annoying, although I'm sure there are plenty of people that such a feature benefits. Thankfully, there is a way to turn this feature of. In the PHP.ini file, there is an option for magic_quotes_gpc. If this is on, everything is automatically escaped (slashed). Otherwise, if it is off, things will be as normal.

Just thought I'd pass the information along for other curious minds.
Just my $.02 :-)
Ti Powerbook 1Ghz w/ Superdrive ......and lovin' it! :)
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:45 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2