Posted by Hendri Kurniawan on 05/11/07 02:49
Mike P2 wrote:
> On May 10, 10:38 pm, Hendri Kurniawan <ask...@email.com> wrote:
>> Man-wai Chang wrote:
>>
>>> How could I check whether a string variable contains nothing but space?
>>> empty() does not work unless the string variable is "".
>> empty(trim($variable));
>>
>> Hendri Kurniawan
>
> Actually, that will return false if the string is ' 0 ' because the
> number 0 is considered emptyness by empty(). The right way to do it
> is:
>
> if( trim( $variable ) == '' )
>
> empty() will also make sure the variable is set for you. You don't
> have this luxury since you are using trim() and an operator, so you
> may have to do this instead:
>
> if( !isset( $variable ) || trim( $variable ) == '' )
>
> ...if you are validating input.
>
> -Mike PII
>
Yes true :)
Hendri Kurniawan
[Back to original message]
|