Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
| Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 10th, 2004, 05:47 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default add slashes and strip slashes

I have noticed a strange thing in PHP hosted under windows 2003.

I use addslashes function to remove any single quotes before inserting input data to db. Then I need to use stripslashes function while displaying it.

If I use

str_replace("'", "\'", $str_input)

instead of addslashes, I don't have to use stripslashes function. A single quote is getting inserted as a single quote itself in this case. Where as when I use addslashes, it is getting added as \' into the database.

I thought the above statement and addslashes are doing the same thing.

May I know why this is happening ? Is there any automatic replacement of single quotes ?

Thanks

Madhu
Reply With Quote
  #2 (permalink)  
Old December 10th, 2004, 08:30 AM
Authorized User
 
Join Date: Oct 2004
Location: Edinburgh, Scotland, United Kingdom.
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to SiliconFuRy
Default

if u want to remove single quotes, then just do

str_replace("'","",$str_input);

Many shoes,

Jamez/SiliconFuRy
Reply With Quote
  #3 (permalink)  
Old December 10th, 2004, 08:52 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

Sorry for not presenting the problem correctly. My aim is not to remove single quotes from inputs. But retain them as single quote itself in database. If I am using addslashes function, the single quotes in inputs are getting stored as \' in database. I just want to store only ' in database.
Reply With Quote
  #4 (permalink)  
Old December 13th, 2004, 05:18 AM
Authorized User
 
Join Date: Oct 2004
Location: Edinburgh, Scotland, United Kingdom.
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to SiliconFuRy
Default

Look up the PHP manual for magic quotes.

Many shoes,

Jamez/SiliconFuRy
Reply With Quote
  #5 (permalink)  
Old December 14th, 2004, 07:12 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

use addslashes($html_content) before dumping into db.
use stripslashes($html_content) before html displaying.
this should work well in win2003/iis

Reply With Quote
  #6 (permalink)  
Old December 27th, 2004, 04:57 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

I thought we should follow standard: addslahes() when iserting into db -n- stripslashes() when outputting into files. But some serves have 'magic_quotes_gpc On' I used ini_set(magic_quotes_gpc, 'Off'); but its not working. Else I've to modify PHP source code.


Reply With Quote
  #7 (permalink)  
Old December 27th, 2004, 05:37 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

Yes, that magic_quotes_gpc and magic_quotes_runtime are playing something here. I am currently doing a thorough research. I hope to publish a function soon.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting 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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql is stripping slashes in serialized array harpua PHP Databases 1 December 5th, 2007 07:16 AM
how do I strip a URL down to the filename? mikehsu317 VBScript 1 July 3rd, 2005 02:52 AM
lost slashes when passing in param bleitner Javascript 5 August 20th, 2004 10:01 AM



All times are GMT -4. The time now is 12:09 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.