Page 1 of 1

Replacing unwanted chars in a string

Posted: Fri Feb 07, 2003 2:07 pm
by megaming
Hi,

How would I get rid of speech marks and anything else that could mess up my mysql database from $var ?

I guess i'd use preg_replace but I dunno what to replace and how to find it.

Posted: Fri Feb 07, 2003 2:26 pm
by daven
mysql_escape_string($var)

Posted: Fri Feb 07, 2003 2:32 pm
by megaming
really, is that it?!

will that work in my cron script too do you think?

Posted: Fri Feb 07, 2003 5:04 pm
by lazy_yogi
what's a cron script ?

I've heard "crons job" before but dunno what it is

Posted: Fri Feb 07, 2003 6:48 pm
by JPlush76
cron is an automated script you schedule on unix boxes to run your php or other scripts at certain times. so if you wanted an email every night at midnight on how many customers signed up that day... you would write the php script that does it and then use a crontab to execute it at midnight.

and that function will work with a cron, any php commands will. its just executing a php page basically at a certain time

Posted: Sat Feb 08, 2003 3:09 am
by megaming
It is still letting quotation marks into my database!!

Help :(

Posted: Sun Feb 09, 2003 5:26 am
by megaming
anyone?!

Please!!

Posted: Sun Feb 09, 2003 1:18 pm
by JPlush76
addslashes()

and then stripslashes()

Posted: Sun Feb 09, 2003 1:23 pm
by hob_goblin
It's letting quotes in, but they won't be messing up your database.

Posted: Sun Feb 09, 2003 1:31 pm
by Stoker
if you want to strip anything but let's say 0-9,A-Z, dot, comma and dash you could do something like

$safetext = preg_replace('/[^A-z0-9,.\-]/','',$unsafevar);