#10234 [Com]: if (... != ...) does not work properly with strings
| From: | only-pvc540 at hotmail dot com | Date: | Tue, 20 Jul 2004 15:00:18 +0000 |
| Subject: | #10234 [Com]: if (... != ...) does not work properly with strings | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-62772@lists.php.net to get a copy of this message | ||
ID: 10234
Comment by: only-pvc540 at hotmail dot com
Reported By: ruslan2000 at mail dot com
Status: Bogus
Bug Type: Unknown/Other Function
Operating System: Win2000 Prof
PHP Version: 4.0.4pl1
New Comment:
<a href=http://only-realtime-pvc-u.da.ru>only
pvc</a>
Previous Comments:
------------------------------------------------------------------------
[2001-04-08 15:08:31] cnewbill@php.net
For string comparison use !== for NOT and === for EQUALS.
-Chris
------------------------------------------------------------------------
[2001-04-08 14:58:54] ruslan2000 at mail dot com
<?php
/*
I want to compare two strings and if they are equal show a message on
the screen.
But I discovered that it's imposible, because PHP think that they are
equal anyway :(((
Example of script
*/
//EX 1. something wrong
$qqq = "00041001001001001001001001001001001002000";
$xxx = "00041001001001001000000000000000000000000";
# with != just the same effect as <>
if ($qqq <> $xxx)
echo "<hr>$qqq<br> <b>!=</b> <br>$xxx<hr>"; //it
should be on the
screen, but ...
else
echo "<hr>$qqq<br> <b>=</b> <br>$xxx <hr>";
//it's appear every time
on the screen :(((
if ($qqq != $xxx)
echo "<hr>$qqq<br> <b>!=</b> <br>$xxx";
else
echo "<hr>$qqq<br> <b>=</b> <br>$xxx <hr>";
//(strval($qqq) != strval($xxx)) does not work too
if (strval($qqq) != strval($xxx))
echo "<hr>$qqq<br> <b>!=</b> <br>$xxx<hr>";
else
echo "<hr>$qqq<br> <b>=</b> <br>$xxx <hr>";
//EX 2 - all OK
$qqq = "00041001000000000000000000000000000000000";
$xxx = "00041001001001001001001001001001001002000";
# with != just the same effect as <>
if ($qqq <> $xxx)
echo "$qqq<br> <b>!=</b> <br>$xxx";
else
echo "$qqq<br> <b>=</b> <br>$xxx <hr>";
if ($qqq != $xxx)
echo "$qqq<br> <b>!=</b> <br>$xxx";
else
echo "$qqq<br> <b>=</b> <br>$xxx <hr>";
?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=10234&edit=1