On 10/12/06, Richard Lynch <[EMAIL PROTECTED]> wrote:
My take:
$number = (int) $number;
if ($number < 1) $number = 1;
You could error out for < 1, or compare the original with the (int)
cast to see if PHP considers them = and error out if not, while using
the (int) cast to be SURE you have an
My take:
$number = (int) $number;
if ($number < 1) $number = 1;
You could error out for < 1, or compare the original with the (int)
cast to see if PHP considers them = and error out if not, while using
the (int) cast to be SURE you have an int, or...
But a typecast and inequality test should be
is_numeric will return true for a positive or negative number.
# [EMAIL PROTECTED] / 2006-12-06 23:51:45 +0200:
> >> How can I ensure that a variable contains a postive integer number?
> >> I'm currently using this code:
> >>
> >> $number=(1-$number);
> >> $number=(1-$number);
> >> if ( $number<1 ) { $number=1; }
> >>
> >> But I'm sure that there is a
ican Student Loan Services
www.americanstudentloan.com
-Original Message-
From: Brad Fuller [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 06, 2006 2:20 PM
To: 'php php'
Subject: RE: [PHP] Ensuring that variable contains a number
> How can I ensure that a variable contains a postive int
sage-
From: Brad Fuller [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 06, 2006 2:20 PM
To: 'php php'
Subject: RE: [PHP] Ensuring that variable contains a number
> How can I ensure that a variable contains a postive integer number?
> I'm currently using this code
> How can I ensure that a variable contains a postive integer number?
> I'm currently using this code:
>
> $number=(1-$number);
> $number=(1-$number);
> if ( $number<1 ) { $number=1; }
>
> But I'm sure that there is a better way. What would that be?
this will check that $input is a posi
On 06/12/06, Melanie Maddix <[EMAIL PROTECTED]> wrote:
[snip]
How can I ensure that a variable contains a postive integer number?
[/snip]
Hi Dotan,
Check the php manual for is_int() and is_numeric().
Thanks, Melanie. I completely forget- I already knew about those
functions! That's what happ
How can I ensure that a variable contains a postive integer number?
I'm currently using this code:
$number=(1-$number);
$number=(1-$number);
if ( $number<1 ) { $number=1; }
But I'm sure that there is a better way. What would that be?
Dotan Cohen
http://what-is-what.com/what_is/internet
9 matches
Mail list logo