Online computer courses, code, programming tutorial and sidebar information for monitoring Canadian S&P/TSX index. Build friendship and networking. Welcome to visit my blogs often!!! I also have two other sites: YouTube Channel and Google site.
Adsense
Popular Posts
- PHPWind-- A PHP forum script applcaition in China
- Using Cron Job to process PHP scripts
- job interview questions (1)
- Free host forum is not reliable
- Powerful js library datable to export table in pdf, excel, sorting, freezing column and table header fixed (sticky)
- PHP connect IBM db2 database in XAMPP
- Set up a child account and set screen time limit in Windows 8
- Datatable export excel wraptext and newline
- phpexcel toggle expand and hide column in EXCEL and summary
- Install PHPMailer 5.2.4 and use smtp gmail
Friday, March 15, 2013
PHP, input verification
In this PHP example, we allow input as ubc, vch, others. The input is not case sensitive and allow users some typo, such as add . between letters such as u.b.c., also type others as other.
//First remove all . and convert to lower case, using PHP function trim to ignore white spaces.
$site=strtolower(str_replace(".", "",trim($_POST['site'])));
//Create an array containing strings allowed
$site_allow = array("ubc","vch","others","other");
//Using PHP function in_array to check string $site match any element of the array
if(!in_array($site,$site_allow)){
$record['error'][] = 'Invalid site category';
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment