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,
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
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.
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",
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
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
> -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
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
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.
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
">
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
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:
>> > >>
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
> -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
[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
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?
>>
>>
>
> 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
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
>> >
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
> back -1, 0, or 1 depending upon their alphabetical
I had never completely read over the rules with regard to comparisons in
PHP, and was recently alarmed to find that $str1 == $str2 might not
compare the way I thought they would. Is it common practice among PHP
coders to use strcmp() instead of == in making string comparisons? Or am
I missing/misre
- 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/
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: $
Hi All,
I must be overlooking something here ...
$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: $var1 < $v
23 matches
Mail list logo