[thelist] Form validation function in PHP

jon steele jjsteele22 at yahoo.com
Sun Jun 9 12:35:01 CDT 2002


Maybe you should use:

eval("\$$variable")

So if $variable is "name", it will return $name.

Jon

--- David Bindel <dbindel at austin.rr.com> wrote:
> I am trying to write a PHP function that checks to see if a
> specified variable has been set and is not empty so I don't
> have to write a bunch of code for each variable I want to
> check.
>
> I have tried using the isset() and empty() functions to
> check whether $myvar exists and is not empty this using the
> following code, but apparently, PHP cannot evaluate a string
> which is the name of a variable ("$myvar"):
>
> function filled($variable) {
> 	if (isset(eval($variable)) && !empty(eval($variable))) {
> 		return true;
> 	} else {return false;}
> }
> echo filled("\$myvar");
>
> But it gives me this error:
> Parse error: parse error, unexpected T_EVAL, expecting
> T_VARIABLE or '$' in .....
>
> Does anyone know how I can make this function work right?
>
> TIA,
> David Bindel

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



More information about the thelist mailing list