User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 397,853 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,361 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting

Replacing 2 characters with with preg_replace

Join Date: Oct 2007
Posts: 174
Reputation: Venom Rush is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
Venom Rush's Avatar
Venom Rush Venom Rush is offline Offline
Junior Poster

Replacing 2 characters with with preg_replace

  #1  
Jan 15th, 2008
Hi there

I'm using preg_replace to replace ' and " with a backslash in front of them so that I don't get problems with my MySQL INSERT queries. But at the moment I can only replace them with one charater as below:

  1. $unedited = $_POST['content'];
  2. $content = preg_replace("/['|\"]/", "\'", $unedited);

At the moment that just replaces both ' and " with ' which isn't ideal. Can anyone tell me how I'd be able to replace them with the respective charater. (e.g. ' would be replaced with \' and " would be replaced with\")
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 8:22 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC