Home  >  Article  >  Backend Development  >  PHP function strcoll() that compares two strings (according to local settings)

PHP function strcoll() that compares two strings (according to local settings)

黄舟
黄舟Original
2017-11-04 09:14:161210browse

Example

ComparisonString:

<?php
setlocale (LC_COLLATE, &#39;NL&#39;);
echo strcoll("Hello World!","Hello World!");
echo "<br>";

setlocale (LC_COLLATE, &#39;en_US&#39;);
echo strcoll("Hello World!","Hello World!");
?>

Definition and usage

strcoll() function compares two strings.

The comparison of strings changes depending on the local setting (A8866508e6f635ebe7431948a1ce090eda).

Note: strcoll() is case-sensitive, but not binary safe.

Note: If the current locale is C or POSIX, this function works the same as strcmp().

Syntax

strcoll(string1,string2)
Parameters Description
string1 Required. Specifies the first string to compare.
string2 Required. Specifies the second string to be compared.

Technical details

##PHP version: Update LogExample
Return value: This function returns:
  • 0 - if the two strings are equal

  • ##8f029751ac12f19769820fc6523b37120 - if string1 Greater than string2

4.0.5+
: Since PHP 4.2.3, this function can work on win32.
<?php
setlocale (LC_COLLATE, &#39;NL&#39;);
echo strcoll("Hello World!","Hello WORLD!");
echo "<br />";
setlocale (LC_COLLATE, &#39;en_US&#39;);
echo strcoll("Hello World!","Hello WORLD!");
?>

Output:

-1 1

The above is the detailed content of PHP function strcoll() that compares two strings (according to local settings). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn