★ wanayoo — archive 1999 http://www.php.net/manual/it/function.strcmp.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Strings
Quick Reference
English version of this pageGerman version of this pageJapanese version of this pageFrench version of this pageHungarian version of this page
Strings
* AddCSlashes
* AddSlashes
* bin2hex
* Chop
* Chr
* chunk_split
* convert_cyr_string
* count_chars
* crypt
* echo
* explode
* flush
* get_html_translation_table
* get_meta_tags
* htmlentities
* htmlspecialchars
* implode
* join
* ltrim
* md5
* Metaphone
* nl2br
* Ord
* parse_str
* print
* printf
* quoted_printable_decode
* QuoteMeta
* rawurldecode
* rawurlencode
* setlocale
* similar_text
* soundex
* sprintf
* strcasecmp
* strchr
* strcmp
* strcspn
* strip_tags
* StripCSlashes
* StripSlashes
* stristr
* strlen
* strpos
* strrchr
* str_repeat
* strrev
* strrpos
* strspn
* strstr
* strtok
* strtolower
* strtoupper
* str_replace
* strtr
* substr
* substr_replace
* trim
* ucfirst
* ucwords
Manual: strcmp
View the source code for this pageSearch the site



Previous page
 strchr
 Updated
Sun, 06 Aug 2000
strcspn 
Next page


strcmp

(PHP3 , PHP4 )

strcmp -- Binary safe string comparison

Description

int strcmp (string str1, string str2)

Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.

Note that this comparison is case sensitive.

See also ereg(), strcasecmp(), substr(), stristr(), and strstr().


User Contributed Notes: strcmp


kiss@ism.co.kr
02-Nov-1999 02:34
strcasecmp() function is available from
version 3.0.2. It is case insensitive string compare function.



frewuill@merlin-corp.com
28-Feb-2000 02:49
Hey be sure the string you are comparing has not special characters like '\n' or something like that.


no@localhost
15-Jul-2000 06:17
I would love to see a function like strncmp() from C -- where you can specify the number of characters to do a compare on. Also, I suppose, the case insensitive version for this would be good too.



My current workaround is somewhat silly.



$Long = "This is a very long string";

$Short = "This";

if ($Short == substr($Long, 0, strlen($Short))) ... do something



It just looks confusing.



waddell@caravan.com
15-Jul-2000 11:05
Yes, a strncmp function would be nice. But, php
now has so many functions that I'd hate to add another if an easy workaround exists. Perhaps, adding length as an optional third arg?



Jesse@bend.com
26-Jul-2000 10:15
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..

both strcmp and strcasecmp are thus rendered totally unuseable for me in order to either alphebetize or compare strings for inequality.



phpnotes@travelersweb.com
31-Jul-2000 08:18
Here is a quick note to explain what is meant by > and <. I wrote a script to compare results. If a string is closer to 'A' in the alphabet, it is < the other string. Here is the output hope this save saves people lots of time:

acc = acc | ac < acc

accc > acc | acd > acc

acb < acc | acb < accc

acb < accd | bcc > acc

bcc > acc | bcca > acc

bcc > acca | 1bcc < acca

bcc < bcc1 | bcc1 > bcc

1bcc < bcc | 1bcc < 1bcd

1bcd > 1bcc | _bcc < bcc

bcc > _bcc | ;bcc < bcc

bcc > ;bcc | bcc < bcc;

bcc; = bcc;



 About Notes


Previous page
 strchr
 Updated
Sun, 06 Aug 2000
strcspn 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.