| 
	
 | 
 Posted by Jochem Maas on 06/16/38 11:33 
Steve Edberg wrote: 
> Only problem with intval() is that it returns 0 (a valid value) on  
 
I knew that. :-) 
 
> failure, so we need to check for 0 first. Adding more secure checks  
 
do we? given that FALSE casts to 0. 
 
> would make this more than just a one-liner,  eg; 
>  
> $_CLEAN['x'] = false; 
> if (isset($_POST['x'])) { 
>    if (0 == 1*$_POST['x']) { 
 
I find the 1*_POST['x'] line a bit odd. why do you bother with the '1*' ? 
 
>       $_CLEAN['x'] = 0; 
>    } else { 
>       $x = intval($_POST['x']); 
>       if ($x > 0 && $x == 1*$_POST['x']) { 
 
this is wrong ... if $_POST['x'] is '5.5' this won't fly 
but is valid according to the OP. 
 
>          $_CLEAN['x'] = $x; 
>       } 
>    } 
> } 
>  
> Reducing to a two-liner, if you *really* want: 
>  
> $x = intval(@$_POST['x']); 
> $_CLEAN['x'] = (isset($_POST['x']) ? ((0 == 1*$_POST['x']) ? 0 : (($x >  
> 0 && $x == 1*$_POST['x']) ? $x : false)) : false); 
>  
> (all untested) 
>  
> That *should* return false unless all your conditions are set, in which  
> case it will return your cardinal number (non-negative integer). 
>  
> Disclaimer: Currently operating on caffeine deficit; it's possible I'm  
> answering a question no one asked. 
 
now that is funny :-)
 
  
Navigation:
[Reply to this message] 
 |