Re: [PHP] Ensuring that variable contains a number

2006-12-09 Thread Dotan Cohen
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

Re: [PHP] Ensuring that variable contains a number

2006-12-09 Thread Richard Lynch
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

Re: [PHP] Ensuring that variable contains a number

2006-12-07 Thread Dave Goodchild
is_numeric will return true for a positive or negative number.

Re: [PHP] Ensuring that variable contains a number

2006-12-07 Thread Roman Neuhauser
# [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

Re: [PHP] Ensuring that variable contains a number

2006-12-06 Thread Dotan Cohen
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

RE: [PHP] Ensuring that variable contains a number

2006-12-06 Thread Ray Hauge
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

RE: [PHP] Ensuring that variable contains a number

2006-12-06 Thread Brad Fuller
> 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

Re: [PHP] Ensuring that variable contains a number

2006-12-06 Thread Dotan Cohen
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