Page 1 of 1

Allowing quotes in preg_replace, please help

Posted: Fri Jan 28, 2011 2:00 am
by robertbarzyk
im using preg_replace to filter coming from a form.

i'd like to allow double quotes and single quotes could somebody help me out.

-This is what i have currently!

$t1 = preg_replace("/[^a-z0-9\/!?:,.;$><_ ]/", '', $title);

Re: Allowing quotes in preg_replace, please help

Posted: Fri Jan 28, 2011 7:02 am
by Peec
escape them.

like so
\" \'

Re: Allowing quotes in preg_replace, please help

Posted: Fri Jan 28, 2011 8:38 am
by robertbarzyk
Thanks, i know im doing something else wrong... probably real simple

this is my code now

$t1 = preg_replace("/[^a-z0-9\/!?\" \' :,.;$><_ ]/", '', $title);

mysql_query("INSERT INTO pages SET
title='$t1',
num='$num'");

it will allow double quotes but not single quotes... what am i doing wrong?