You are here: cleaning up code Q1 « All PHP « IT news, forums, messages
cleaning up code Q1

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация