Re: Verifying a certain amount of numbers
| From: | Curt Zirzow | Date: | Wed, 16 Jul 2003 16:19:25 +0000 |
| Subject: | Re: Verifying a certain amount of numbers | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-155462@lists.php.net to get a copy of this message | ||
Justin French <justin@indent.com.au> wrote:
> If you care about performance at all, try and find away around the
> problem without regular expressions...
>
> I tested
>
> if( (strlen($str) == 6) && (is_int($str)) )
>
I did some more tests on this problem is that $str is still considered a
string and not an integer here is my test script and results:
<?php
// is_int() testing
// standard string
$str = "123";
if (is_int($str)) print "$str: yes \n";
else print "$str: no \n";
//cast to integer
$str = (integer)"123";
if (is_int($str)) print "$str: yes \n";
else print "$str: no \n";
// implied cast to integer
$str = "123";
$str += 0;
if (is_int($str)) print "$str: yes \n";
else print "$str: no \n";
// force to be integer
$str = "123";
settype($str, 'integer');
if (is_int($str)) print "$str: yes \n";
else print "$str: no \n";
/*
Results:
123: no
123: yes
123: yes
123: yes
*/
?>