Re: checkng if string is a number

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



  Curt,

  yes, technically, 0 is a number - it's a bit late here, and I believe I
mis-understood the original question, which is why I re-posted in the thread.

  I guess my mind got a bit confused by the combination of "is_int doesn't
work", "intval returns a number" and "'10' vs 'ten'" example.

  That's probably due to the fact I normally rely on intval() to do the job
for integers, which also helps "remove" some user mis-types at the end of
number fields, which is useful in situations when
A) you're ok with the user typing 11l when they mean 111
B) you don't want to accept a value of 0

  In principle, that's the only problem with "intval" - a "0" will evaluate
 as false in a logical statement. Unless one wants to make sure it's a full
 number from start to end, of course...

  Max.

On Thursday 17 November 2005 23:05, you wrote:
> On Thu, Nov 17, 2005 at 08:47:30PM +0100, Max Belushkin wrote:
> >   extras you're using?) the following script works fine:
> >
> > <?php
> >   if (10==intval("ten")) echo "boo\n"; else echo "no boo\n";
> > ?>
> >
> >   I get no boo. intval doesn't convert my "ten" to a number.
> >   Moreover, the output of the following:
>
> Yes it does.
>
>   echo intval('a'); // 0
>   echo intval('0'); // 0
>   echo intval(0);   // 0
>   echo intval(0.1); // 0
>
>   $v = intval('ten');
>   var_dump($v); // int(0)
>
>   $v = intval('10');
>   var_dump($v); // int(10)
>
> Curt.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux