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

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

黄舟
Release: 2023-03-17 06:20:02
Original
1293 people have browsed it

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!");
?>
Copy after login

Definition and usage

strcoll() function compares two strings.

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

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)
Copy after login
ParametersDescription
string1 Required. Specifies the first string to compare.
string2Required. 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

  • ##<0 - if string1 is less than string2

  • >0 - 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!");
?>
Copy after login

Output:

-1 1
Copy after login

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!

Related labels:
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template