Re: optimizing script...

From: Date: Fri, 15 Feb 2002 18:28:24 +0000
Subject: Re: optimizing script...
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-16982@lists.php.net to get a copy of this message
Hello... Try this... $pat = array("\", "@", "*", "&", "%"); $with = (_) \\What ever you want... $car_year = str_replace ($pat, $with, stripslashes($car_year)); echo $car_year; This would work with ONE VARIABLE... I suppose maybe you could make the Variables($car_type,$car_model,$car_year) into an array. Then ereg_replace the new array, then turn it back to the variables...I think it's explode...and implode.... Never tried it.... Good Luck Dan On Thursday, February 14, 2002, at 10:57 PM, jlgerfen@hotmail.com wrote:
I have a script that prevents invalid characters from being passed from a html form to a mysql database using php and I am wondering if there is a way to condense it so instead of declaring the ereg_replace for each field in the html form, to simply use one function to remove invalid characters and html markup from all the fields in the form at once... here is my code, any insight would be great. I am not asking you to do it for me, I just want to know how and what the best way to condense it would be. Thanks in advance. Jas # --------- Error correction for car_type field -------- $car_type = ereg_replace ("\"", "&q&", $car_type); $car_type = ereg_replace ("'", "&a&", $car_type); $car_type = ereg_replace ("%", "&p&", $car_type); $car_type = ereg_replace ("\\\\", "&bs&", $car_type); # --------- Error correction for car_model field -------- $car_model = ereg_replace ("\"", "&q&", $car_model); $car_model = ereg_replace ("'", "&a&", $car_model); $car_model = ereg_replace ("%", "&p&", $car_model); $car_model = ereg_replace ("\\\\", "&bs&", $car_model); # --------- Error correction for car_year field -------- $car_year = ereg_replace ("\"", "&q&", $car_year); $car_year = ereg_replace ("'", "&a&", $car_year); $car_year = ereg_replace ("%", "&p&", $car_year); $car_year = ereg_replace ("\\\\", "&bs&", $car_year); -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.db (#16982) next »