[Openfirst-cvscommit] base/includes functions.php,1.5,1.6
Brought to you by:
xtimg
From: Astronouth7303 <ast...@us...> - 2005-08-17 16:36:25
|
Update of /cvsroot/openfirst/base/includes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29153/includes Modified Files: functions.php Log Message: added ofConvert2Bool() Index: functions.php =================================================================== RCS file: /cvsroot/openfirst/base/includes/functions.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** functions.php 17 Aug 2005 16:07:59 -0000 1.5 --- functions.php 17 Aug 2005 16:36:16 -0000 1.6 *************** *** 112,114 **** --- 112,143 ---- return implode(PHP_EOL, $rtn); } + + /** Converts input to boolean + * returns true on: yes, y, true, 1 + * returns false on: no, n, false, 0 + * returns nothing if neither (return;). + * if a value is in both $moretrue and $morefalse, it is treated as true + * case-insensitive + */ + function ofConvert2Bool($text, $moretrue=array(), $morefalse=array()) { + $yesvals = $moretrue; + $yesvals[] = 'yes'; + $yesvals[] = 'y'; + $yesvals[] = 'true'; + $yesvals[] = '1'; + + $novals = $morefalse; + $novals[] = 'no'; + $novals[] = 'n'; + $novals[] = 'false'; + $novals[] = '0'; + + foreach ($yesvals as $val) { + if (strcasecmp($text, $val) == 0) return true; + } + foreach ($novals as $val) { + if (strcasecmp($text, $val) == 0) return false; + } + return; + } ?> |