Allowing quotes in preg_replace, please help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
robertbarzyk
Forum Newbie
Posts: 19
Joined: Tue Oct 06, 2009 4:12 pm

Allowing quotes in preg_replace, please help

Post 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);
Peec
Forum Commoner
Posts: 33
Joined: Fri Feb 22, 2008 3:58 am

Re: Allowing quotes in preg_replace, please help

Post by Peec »

escape them.

like so
\" \'
robertbarzyk
Forum Newbie
Posts: 19
Joined: Tue Oct 06, 2009 4:12 pm

Re: Allowing quotes in preg_replace, please help

Post 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?
Post Reply