downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

strcspn> <strcmp
[edit] Last updated: Sat, 07 Jan 2012

view this page in

strcoll

(PHP 4 >= 4.0.5, PHP 5)

strcollLocale-basierter Zeichenkettenvergleich

Beschreibung

int strcoll ( string $str1 , string $str2 )

Beachten Sie, dass der Vergleich Groß- und Kleinschreibung berücksichtigt. Im Gegensatz zu strcmp() ist die Funktion zudem nicht binary safe.

strcoll() legt dem Vergleich die aktuellen locale-Angabe zu Grunde. Ist deren Wert C oder POSIX, verhält sich diese Funktion äquivalent zu strcmp().

Parameter-Liste

str1

Die erste Zeichenkette.

str2

Die zweite Zeichenkette.

Rückgabewerte

Gibt einen Wert <0 zurück, wenn str1 kleiner ist als str2, einen Wert >0, wenn str1 größer ist als str2, und 0, wenn sie gleich sind.

Changelog

Version Beschreibung
4.2.3 Die Funktion ist jetzt auch unter Win32-Systemen nutzbar.

Siehe auch

  • preg_match() - Führt eine Suche mit einem regulären Ausdruck durch
  • strcmp() - Vergleich zweier Strings (Binary safe)
  • strcasecmp() - Vergleich von Zeichenketten ohne Unterscheidung der Groß- und Kleinschreibung (Binary safe)
  • substr() - Gibt einen Teil eines Strings zurück
  • stristr() - Wie strstr, aber unabhängig von Groß- bzw. Kleinschreibung
  • strncasecmp() - Binärdaten-sicherer und groß- und kleinschreibungs-unabhängiger Stringvergleich der ersten n Zeichen
  • strncmp() - String-Vergleich der ersten n Zeichen (Binary safe)
  • strstr() - Findet das erste Vorkommen eines Strings
  • setlocale() - Setzt Locale Informationen



add a note add a note User Contributed Notes strcoll
sakkarinlaohawisut15 at hotmail dot com 22-Mar-2003 04:31
strcoll()'s behavior is sometimes a little bit confusing. It depends on LC_COLLATE in your locale.

<?php

 $a
= 'a';
 
$b = 'A';

 print
strcmp ($a, $b) . "\n"; // prints 1

setlocale (LC_COLLATE, 'C');
 print
"C: " . strcoll ($a, $b) . "\n"; // prints 1

 
setlocale (LC_COLLATE, 'de_DE');
 print
"de_DE: " . strcoll ($a, $b) . "\n"; // prints -2

 
setlocale (LC_COLLATE, 'de_CH');
print
"de_CH: " . strcoll ($a, $b) . "\n"; // prints -2

 
setlocale (LC_COLLATE, 'en_US');
 print
"en_US: " . strcoll ($a, $b) . "\n"; // prints -2

?>

This is useful e. g. if want to sort an array by using strcoll:

<?php

 $a
= array ('a', 'A', 'ä', 'Ä', 'b', 'B');

 
setlocale (LC_COLLATE, 'C');
 
usort ($a, 'strcoll');
 
print_r ($a);

?>

This is like sort($a):
 Array
 (
    [0] => A
    [1] => B
  [2] => a
    [3] => b
    [4] => Ä
    [5] => ä
 )

<?php

 setlocale
(LC_COLLATE, 'de_DE');
usort ($a, 'strcoll');
 
print_r ($a)

?>

This is completely different:
 Array
 (
    [0] => a
    [1] => A
    [2] => ä
    [3] => Ä
    [4] => b
  [5] => B
 )
27-Aug-2002 01:05
Note that some platforms implement strcmp() and strcasecmp() according to the current locale when strings are not binary equal, so that strcmp() and strcoll() will return the same value! This depends on how the PHP strcmp() function is compiled (i.e. if it uses the platform specific strcmp() found in its standard library!).
In that case, the only difference between strcoll() and strcmp() is that strcoll() may return 0 for distinct strings(i.e. consider strings are equal) while strcmp() will differentiate them if they have distinct binary encoding! This typically occurs on Asian systems.
What you can be sure is that strcmp() will always differentiate strings that are encoded differently, but the relative order may still use the current locale setting for collation order!

 
show source | credits | stats | sitemap | contact | advertising | mirror sites