On Mon, May 23, 2011 at 9:32 AM, Joshua Kehn <josh.kehn@xxxxxxxxx> wrote: > > On May 23, 2011, at 9:28 AM, Alex Nikitin wrote: > > > There is an interesting note in the comments for strcmp: > > "Well, I am using PHP 4.0 and both strcmp and strcasecmp appear to be > giving me very arbitrary and incomprehensible results. When I input strings, > it appears that "equal" strings return "1", as well as some unequal strings, > and that if the first argument is "smaller" then I *tend* to get negative > numbers, but sometimes I get 1, and if larger I *tend* to get numbers larger > than 1.. " > > > > > > Guessing that earlier versions of php 4 and before would give the results > that would have values other then 1, 0, -1, i looked through the change log, > but nothing immediately jumped out, there was a lot of mbstring work done, > and they did add the nat comparison functions, and play with the pcre engine > a bit, which could have caused this as an unintended result for a few > versions, i think though it was a bug at some point, so, maybe a php dev > would chime in if they remember...? > > > > > > -- Alex -- > > -- > > The trouble with programmers is that you can never tell what a programmer > is doing until it’s too late. ~Seymour Cray > > > All this confusion makes me glad that I'm using === for equality checks > instead of strcmp. > > Regards, > > -Josh > ____________________________________ > Joshua Kehn | Josh.kehn@xxxxxxxxx > http://joshuakehn.com > > It depends on what you need to check, josh :) If you wanted to say find an anagram, or do a search with some typo correction, strcmp can be many times more helpful then a ===, that said comparing 2 strings to be equal === works about 20% quicker, so it works better for comparing two strings for equality (or unequality) anyways. There is no confusion, strcmp has a documented way in which it is to work in posix-compliant languages, ISO/IEC 9899:1999, 7.21.4.2, so as long as you follow the ISO guidelines for the scrcmp checking, your code should work correctly... -- The trouble with programmers is that you can never tell what a programmer is doing until it’s too late. ~Seymour Cray