|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-10-15 23:49 UTC] cdfisher at swbell dot net
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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 16:00:01 2025 UTC |
roman@freepuppy ~ 1036:0 > php -r 'var_dump(urldecode("%3CItemNumber%3E427-1831A"));' string(21) "<ItemNumber>427-1831A" fix your code.