[solved]preg_replace help?

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

[solved]preg_replace help?

Post by dreamline »

Hi guyz,
First of all i'm not an preg expert yet, so here's my problem. In PHP magic quotes is enabled however if i submit a form with quotes (single and double) then when i print it back into the form you see trailing backslashes.. I'm using preg_replace to fix it, however i'm doing it in 2 lines of code as where i am sure i can use only one line of code.. Can anyone help me? Here's what i have

Code: Select all

$test=preg_replace('[\\\"]',""",$_POST["searchname"]);
$test=preg_replace('[\\\]',"",$test);
So basically if $_POST["searchname"] is: "aaa" 'aaa' aaaa

Printing it back into a textbox gives the exact same result: "aaa" 'aaa' aaaa

So that's good, but i want to do it with only 1 line of code. Hope it's possible?

Thanks.... :D
Last edited by dreamline on Thu Sep 22, 2005 1:39 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

why not use stripslashes() ?

well.. you can send arrays to the pattern and replacement arguements....
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

Post by dreamline »

hmmmm... Good one Feyd, haven't thought of that... LOL... Probably because i haven't used that function as of yet.. :)

Good thinking... Thanks.. :)
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

and use htmlentities() to replace .. well, html entities.
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

Post by dreamline »

My problem has been solved.. :


Stripslashes in combo with ereg_replace worked like a charm.. :)
Post Reply