I stand firm on strlen() for the following reasons ...
if(!$var) will sometimes act strangely (has for me in the past) when variables
are set to something other than what you are expecting.
if(isset($var)) will return true if your text field is declared but not filled
in.
if(empty($var)) will return true if $var is set to 0 (for obvious reason) so is
only good for certain instances.
strlen() on the other hand converts the variable to a string and returns a count
of characters. It's never failed or acted funky. For this reason I use it
religiously.
Others might say "well it's extra overhead" to which I reply "I'll take an extra
bazillionth of a second to know for sure I have what I need"
--Joe
On Thu, Feb 22, 2001 at 08:18:22AM -0800, Steve Edberg wrote:
> I would do this:
>
> if (!$AgeChild) $AgeChild = 'NA';
>
> More compact, easier to read (to me, anyway). This presumes that a
> value of '' (empty string, interpreted by PHP as false) is NOT a
> valid value here.
>
> As far as your sniplet goes, it is possible that there may be some
> PHP type-casting issues here, depending on: whether $AgeChild is
> numeric or string; the fact that the STRING "false" isn't equivalent
> to the CONSTANT false, the use of == vs. ===.
>
> Time to check out the docs - specifically the types and variables
> sections (also the functions->variables section)...
>
> - steve
>
>
>
> At 5:07 PM -0600 2/22/01, Jacky@lilst wrote:
> >People
> >I tried to check if teh field has set a vaule in it before submit
> >using isset with the sniplet below
> >
> >if ((isset($AgeChild))=="false") {
> >$AgeChild = "NA";
> >}
> >
> >The resule is that it always displays NA whether or not it has vaule
> >in the field, what is the correct way of using isset for this
> >purpose? Or should I use empty() ?
> >Jack
> >[EMAIL PROTECTED]
> >"There is nothing more rewarding than reaching the goal you set for yourself"
>
>
> --
> +--- "They've got a cherry pie there, that'll kill ya" ------------------+
> | Steve Edberg University of California, Davis |
> | [EMAIL PROTECTED] Computer Consultant |
> | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ |
> +-------------------------------------- FBI Special Agent Dale Cooper ---+
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
--
-------------------------------------------------------------------------------
Joe Stump, PHP Hacker, [EMAIL PROTECTED] -o)
http://www.miester.org http://www.care2.com /\\
"It's not enough to succeed. Everyone else must fail" -- Larry Ellison _\_V
-------------------------------------------------------------------------------
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]