Replacing unwanted chars in a string

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
megaming
Forum Commoner
Posts: 27
Joined: Wed Dec 25, 2002 12:31 pm

Replacing unwanted chars in a string

Post 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.
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post by daven »

mysql_escape_string($var)
megaming
Forum Commoner
Posts: 27
Joined: Wed Dec 25, 2002 12:31 pm

Post by megaming »

really, is that it?!

will that work in my cron script too do you think?
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post by lazy_yogi »

what's a cron script ?

I've heard "crons job" before but dunno what it is
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post 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
megaming
Forum Commoner
Posts: 27
Joined: Wed Dec 25, 2002 12:31 pm

Post by megaming »

It is still letting quotation marks into my database!!

Help :(
megaming
Forum Commoner
Posts: 27
Joined: Wed Dec 25, 2002 12:31 pm

Post by megaming »

anyone?!

Please!!
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

addslashes()

and then stripslashes()
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

It's letting quotes in, but they won't be messing up your database.
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post 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);
Post Reply