|  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
39 + 22 = ?
Subscribe to this entry?

 [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-2019 The PHP Group
All rights reserved.
Last updated: Mon Jun 17 00:01:28 2019 UTC