|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10234 if (... != ...) does not work properly with strings
Submitted: 2001-04-08 14:58 UTC Modified: 2001-04-08 15:08 UTC
From: ruslan2000 at mail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.0.4pl1 OS: Win2000 Prof
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: ruslan2000 at mail dot com
New email:
PHP Version: OS:


 [2001-04-08 14:58 UTC] ruslan2000 at mail dot com
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 ... 
	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";
	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>";
	 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";
	echo "$qqq<br> <b>=</b> <br>$xxx <hr>";

if ($qqq != $xxx)
	echo "$qqq<br> <b>!=</b> <br>$xxx";
	echo "$qqq<br> <b>=</b> <br>$xxx <hr>";



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-04-08 15:08 UTC]
For string comparison use !== for NOT and === for EQUALS.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Dec 09 03:03:42 2022 UTC