Re: [PHP] strcmp()?

2011-05-24 Thread tedd
At 11:10 AM -0700 5/24/11, David Harkness wrote: On Tue, May 24, 2011 at 12:48 AM, Vitalii Demianets wrote: So. to write compatible scripts one should check "< 0", not "== -1". Which matches the documentation: Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2,

Re: [PHP] strcmp()?

2011-05-24 Thread David Harkness
On Tue, May 24, 2011 at 12:48 AM, Vitalii Demianets wrote: > So. to write compatible scripts one should check "< 0", not "== -1". > Which matches the documentation: Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal. David

Re: [PHP] strcmp()?

2011-05-24 Thread Vitalii Demianets
On Monday 23 May 2011 15:00:27 tedd wrote: > >Are you absolutely certain about that? > > > >    echo strcmp('These are nearly equal', 'These are almost equal'), "\n"; > >    echo strcmp('different', 'unequal'), "\n"; > >    echo strcmp('b', 'a'), "\n"; My result is: 13 -17 1 I'm runninng PHP 5.2.

Re: [PHP] strcmp()?

2011-05-23 Thread Richard Quadling
On 23 May 2011 14:28, 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",

Re: [PHP] strcmp()?

2011-05-23 Thread Joshua Kehn
On May 23, 2011, at 9:47 AM, Alex Nikitin wrote: > > 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

Re: [PHP] strcmp()?

2011-05-23 Thread Joshua Kehn
On May 23, 2011, at 9:45 AM, tedd wrote: > At 9:32 AM -0400 5/23/11, Joshua Kehn wrote: >> >> All this confusion makes me glad that I'm using === for equality checks >> instead of strcmp. >> >> -Josh > > -Josh: > > Yes, but what if you were sorting? I know you could use sort(), but there > m

RE: [PHP] strcmp()?

2011-05-23 Thread Ford, Mike
> -Original Message- > From: tedd [mailto:tedd.sperl...@gmail.com] > Sent: 23 May 2011 14:41 > The "which way the arrows point" thing is because I'm dyslexic. > While > I know that "a" appears before "b", it's difficult for me to think > of > 'a' being less than 'b' -- UNLESS -- I think i

Re: [PHP] strcmp()?

2011-05-23 Thread Alex Nikitin
On Mon, May 23, 2011 at 9:32 AM, Joshua Kehn 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

Re: [PHP] strcmp()?

2011-05-23 Thread tedd
At 9:32 AM -0400 5/23/11, Joshua Kehn wrote: All this confusion makes me glad that I'm using === for equality checks instead of strcmp. -Josh -Josh: Yes, but what if you were sorting? I know you could use sort(), but there might be logic where a strcmp() would better solve the problem.

RE: [PHP] strcmp()?

2011-05-23 Thread tedd
At 1:06 PM + 5/23/11, Ford, Mike wrote: (Incidentally, tedd, your test script has the < > signs the wrong way round in the output; plus which they should be < > anyway; plus plus which, you are not applying htmlspecialchars() or whatever to your echoed user input, so values such as ">

Re: [PHP] strcmp()?

2011-05-23 Thread Joshua Kehn
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 re

Re: [PHP] strcmp()?

2011-05-23 Thread Alexey Bovanenko
I checked on php 5.2.4-2 (ubuntu5.12). It returns 1,-1,1 On Mon, May 23, 2011 at 4:00 PM, tedd wrote: > At 8:13 AM + 5/23/11, Ford, Mike wrote: > >> > -Original Message- >> > From: tedd [mailto:tedd.sperl...@gmail.com] >> > >On Sat, 21 May 2011 09:26:02 -0400, tedd wrote: >> > >>

Re: [PHP] strcmp()?

2011-05-23 Thread Richard Quadling
On 23 May 2011 13:24, Joshua Kehn wrote: > On May 23, 2011, at 8:17 AM, tedd wrote: > >>> > Mike: That's interesting. Try the same comparisons here: http://www.webbytedd.com/lcc/citw229/string-compare.php >>> > For me they are 1, -1, and 1. >>> >>> Might that have somethin

RE: [PHP] strcmp()?

2011-05-23 Thread Ford, Mike
> -Original Message- > From: Joshua Kehn [mailto:josh.k...@gmail.com] > Sent: 23 May 2011 13:04 > > On May 23, 2011, at 8:00 AM, tedd wrote: > > > At 8:13 AM + 5/23/11, Ford, Mike wrote: > >> echo strcmp('These are nearly equal', 'These are almost > equal'), "\n"; > >> echo strcm

RE: [PHP] strcmp()?

2011-05-23 Thread Jay Blanchard
[snip][/snip] 5.2.9 yields -1, 0, 1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] strcmp()?

2011-05-23 Thread Joshua Kehn
On May 23, 2011, at 8:17 AM, tedd wrote: >> > Mike: >>> >>> That's interesting. Try the same comparisons here: >>> >>> http://www.webbytedd.com/lcc/citw229/string-compare.php >>> >> > For me they are 1, -1, and 1. >> >> Might that have something to do with the version of PHP running? >> >> >

Re: [PHP] strcmp()?

2011-05-23 Thread tedd
> Mike: That's interesting. Try the same comparisons here: http://www.webbytedd.com/lcc/citw229/string-compare.php > For me they are 1, -1, and 1. Might that have something to do with the version of PHP running? -Josh -Josh: I've written this on two different servers. One is Versi

Re: [PHP] strcmp()?

2011-05-23 Thread Joshua Kehn
On May 23, 2011, at 8:00 AM, tedd wrote: > At 8:13 AM + 5/23/11, Ford, Mike wrote: >> > -Original Message- >> > From: tedd [mailto:tedd.sperl...@gmail.com] >> > >On Sat, 21 May 2011 09:26:02 -0400, tedd wrote: >> > >> The function strcmp() simply evaluates two strings and reports >> >

Re: [PHP] strcmp($var1, $var2) versus if ($var1 < $var2)

2008-05-28 Thread C.R.Vegelin
- Original Message - From: "David Otton" <[EMAIL PROTECTED]> To: "C.R.Vegelin" <[EMAIL PROTECTED]> Cc: "[EMAIL PROTECTED]" Sent: Wednesday, May 28, 2008 12:11 PM Subject: Re: [PHP] strcmp($var1, $var2) versus if ($var1 < $var2) 2008/

Re: [PHP] strcmp($var1, $var2) versus if ($var1 < $var2)

2008-05-28 Thread David Otton
2008/5/28 C.R.Vegelin <[EMAIL PROTECTED]>: > $var1 = "01011090"; $var2 = "010190"; // 2 strings > if ($var1 < $var2) ECHO "var1 < var2"; else ECHO "var1 >= var2"; echo " />"; > $r = strcmp ( $var1 , $var2 ); > if ($r < 0) ECHO "var1 < var2", ""; > > 2nd line says: $var1 >= $var2 > 4th line says: $