RE: [PHP] Re: Strange comparison behaviour
String "info" is converted to integer, which is 0... a) if("info" == "0") b) if("info" === 0) c) if("info" == (string)0) Or use strcmp() Cya... Read a book "PHP for beginners" -Original Message- From: Bogdan Stancescu [mailto:[EMAIL PROTECTED] Sent: Friday, May 13, 2005 5:13 AM To: php-general@lists.php.net Subject: [PHP] Re: Strange comparison behaviour You probably mis-typed something: [EMAIL PROTECTED] ~]$ php Content-type: text/html X-Powered-By: PHP/4.3.11 is 0 Cheers, Bogdan Erwin Kerk wrote: > Hi All, > > Can anyone explain me why the following code: > > if ("info" == 0) echo "is 0\n"; else echo "not 0\n"; > > Results in: not 0 > > > Whereas: > > if ("inf" == 0) echo "is 0\n"; else echo "not 0\n"; > > Results in: is 0 > > > > Notice the difference: info in the first sample, inf in the second sample. > > > The used PHP version is PHP 4.1.2 (CLI version) > > > Erwin Kerk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Strange comparison behaviour
On Fri, 2005-05-13 at 06:34, Erwin Kerk wrote: > Bogdan Stancescu wrote: > > You probably mis-typed something: > > > > [EMAIL PROTECTED] ~]$ php > > > if ("info" == 0) echo "is 0\n"; else echo "not 0\n"; > > ?> > > Content-type: text/html > > X-Powered-By: PHP/4.3.11 > > > > is 0 > Tried that, but notice the PHP Version, it is failing in PHP 4.1.2! > > Erwin Kerk Same behavior on 5.x - I suspect something to do with the 'type' and loose comparison operators. According to table 2: http://us4.php.net/manual/en/types.comparisons.php is should evaluate as true. Looking at the ordinal values revealed nothing to me... '; echo ($string == 0) ? "is 0\n" : "not 0\n"; echo (rtrim($string, $lst) == 0) ? "is 0\n" : "not 0\n"; echo "---\n"; for($i=0; $i<$len; $i++) { $ord_value = ord($string[$i]); echo chr($ord_value) . "=" . $ord_value . "\n"; } echo ''; ?> Anyway, I suspect using ($string === 0) will give you the expected results. -- s/:-[(/]/:-)/g BrianGnuPG -> KeyID: 0x04A4F0DC | Key Server: pgp.mit.edu == gpg --keyserver pgp.mit.edu --recv-keys 04A4F0DC Key Info: http://gfx-design.com/keys Linux Registered User #339825 at http://counter.li.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Strange comparison behaviour
is upgrading your php out of the question? i would go with at least 4.3.x if not 5... unless you don't have root access on your server... in which case, i have no advice... On 5/13/05, Erwin Kerk <[EMAIL PROTECTED]> wrote: > Bogdan Stancescu wrote: > > You probably mis-typed something: > > > > [EMAIL PROTECTED] ~]$ php > > > if ("info" == 0) echo "is 0\n"; else echo "not 0\n"; > > ?> > > Content-type: text/html > > X-Powered-By: PHP/4.3.11 > > > > is 0 > Tried that, but notice the PHP Version, it is failing in PHP 4.1.2! > > Erwin Kerk > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- dc .. drewcore.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Strange comparison behaviour
Bogdan Stancescu wrote: You probably mis-typed something: [EMAIL PROTECTED] ~]$ php Content-type: text/html X-Powered-By: PHP/4.3.11 is 0 Tried that, but notice the PHP Version, it is failing in PHP 4.1.2! Erwin Kerk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php