#19926 [NEW]: Can't compare equality on strings using various methods

From: Date: Wed, 16 Oct 2002 04:49:39 +0000
Subject: #19926 [NEW]: Can't compare equality on strings using various methods
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-22542@lists.php.net to get a copy of this message
From: cdfisher@swbell.net Operating system: Win 2K Server PHP version: 4.2.3 PHP Bug Type: Strings related Bug description: Can't compare equality on strings using various methods Here is a part of the script that I use to compare the last part number with the next part number. I have part numbers composed of dashes, numbers and characters (example: 134-4568ATZ). The purpose of this script is to create an XML file for a parts inventory. But the same part may fit many different motorcycles and the CSV file has duplicate part numbers on many rows. They are all sorted by part number so I capture the number I just processed and compare it against the next number. If they match (which is where my problem lies) then instead of creating another part with the same number, I want to add more child elements to the open parent (I wait to close the parent until I get the next row's data). The script where I'm trying the comparism looks like this: if (strcmp($LastPNumber, $data[$i]) != 0){ echo "New number, New Element<br>"; $data[$i] = "\t<" . $elements[$i] .">" . $data[$i] ; } The $data array elements are trimmed as is the $LastPNumber. I have tried the == and === and !== and the the preg_match() function and I am stumped. Here is a readout of the value from comparing, it never changes... --------------------------------------------------------- Comparing the last Part Number (427-1773) to: next Row Part Number: 427-1812A Evaluates to 1 New number, New Element Set the last Part Number to: 427-1812A Comparing the last Part Number (427-1812A) to: next Row Part Number: 427-1812A Evaluates to 1 New number, New Element Set the last Part Number to: 427-1812A Comparing the last Part Number (427-1812A) to: next Row Part Number: 427-1831A Evaluates to 1 ---------------------------------------------------------- 427-1812A above returns the same number (1) as the mis-matches. According to the documentation, the value should be a 0. This is really screwing up my code. I just want to compare strings with strings. I don't care about local or language or having the string be evaluated as an exponent if it has an "e" in it. Do I have to use Java to get a type cast or what? I even tried what some other person suggested, concatenate an empty string in an attempt to force a cast. PHP is such a great tool. Why should something as simple as this be such a problem? Thank you for your help with this. Curtis Fisher -- Edit bug report at http://bugs.php.net/?id=19926&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=19926&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=19926&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=19926&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=19926&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=19926&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=19926&r=support Expected behavior: http://bugs.php.net/fix.php?id=19926&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=19926&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=19926&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=19926&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=19926&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=19926&r=dst IIS Stability: http://bugs.php.net/fix.php?id=19926&r=isapi

« previous php.bugs (#22542) next »