php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ruslan2000 at mail dot com
New email:
PHP Version: OS:

 

 [2001-04-08 14:58 UTC] 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>";

?>

Patches

Pull Requests

History

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

-Chris
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 16:01:31 2025 UTC