Zend - The PHP Company




HTTP

Add Code


small function that validate arguments passed by GET/POST or others  

Type: application
Added by: yszhang
Entered: 12/11/2002
Last modified: 01/11/2001
Rating: - (fewer than 3 votes)
Views: 4696
a small function that can validate arguments passed by GET/POST. can be use on any arguments validation case.


<?
#---------
# validate argument using func_get_args and func_num_args functions
# yinshu 11/11/2002
#---------

function validate () {
        
$args=func_get_args();
        for (
$i=0;$i<func_num_args();$i++) {
                if (
strlen($args[$i])==0) {
                        
// if ($foo) will be false if $foo=0;
                        // strlen will false when null
                        
echo "<b>  Not enough arguments!</b>";
                        
// hide this echo if you don't want extra error message
                        
return FALSE;
                }
        }
        return 
TRUE;    // all argument exist
}

#---------
# usage example, don't copy/paste below
#---------

$one=1;
$two=2;
$zero=0;

if (
validate($one,$two,$zero))
        echo 
"<p>all arguments exist";
else
        echo 
"<p>missing some, or whatever..";

# if any of those arguments is null, validate will return false

if (validate($one,$two,$zero,$three))
        echo 
"<p>all arguments exist";
else
        echo 
"<p>missing some, or whatever..";
?>


Usage Example




Rate This Script





Search



This Category All Categories