|
Posted by Pasquale on 07/21/05 04:59
In my attempts to clean up and improve my PHP coding, I will probably be
submitting questions over the next couple of months as necessary for
everyones input and suggestions. Thanks in advance.
First set of questions. I am using the code below to initialize
variables and filter out unwanted characters from every text input fields.
I'm wondering is this a good or bad idea? If good, can they be put into
an include file for use? Should I be using isset() as in option 2?
I also wanted to add $_POST as in option 3, however the variable may
come from $_SESSION. Should I use $_REQUEST?
option 1:
$address = Filter($address); ## at the top of my scripts
$city = Filter($city); ## at the top of my scripts
option 2:
$address = isset($address) ? Filter($address) : '';
$city = isset($city) ? Filter($city) : '';
option 3:
$address = Filter($_POST['address']);
$city = Filter($_POST['city']);
function Filter () {
$valu = func_get_arg(0);
if (isset($valu) && $valu != "") {
$search = array
("'\~'","'\`'","'\!'","'\@'","'\%'","'\^'","'\&'","'\*'","'\_'","'\+'","'\='","'\{'","'\}'",
"'\['","'\]'","'\|'","'\:'","'\;'","'\"'","'\''","'\<'","'\>'","'\/'","'\\\'","'\s+'");
$replace = array
("","","","","","","","","","","","","","","","","","","","","","","","","
");
$valu = preg_replace($search,$replace,$valu);
$valu = trim($valu);
}
return (isset($valu) && $valu != "") ? $valu : "";
}
Navigation:
[Reply to this message]
|