Page 1 of 1

[solved]preg_replace help?

Posted: Wed Sep 21, 2005 12:27 am
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

Posted: Wed Sep 21, 2005 12:30 am
by feyd
why not use stripslashes() ?

well.. you can send arrays to the pattern and replacement arguements....

Posted: Wed Sep 21, 2005 1:07 am
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.. :)

Posted: Wed Sep 21, 2005 8:57 am
by Jenk
and use htmlentities() to replace .. well, html entities.

Posted: Thu Sep 22, 2005 1:40 am
by dreamline
My problem has been solved.. :


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