The substr_compare () function compares two strings from the specified start length.
This function returns:
0-if the two strings are equal
<0-if string1 (starting position) is smaller than string2
> 0-if string1 (starting position) is greater than string2
Syntax
Substr_compare (string1, string2, startpos, length, case)
*/
$ Str1 = "hello world"; // defines string 1
$ Str2 = "hello world"; // defines string 2
$ Result = substr_compare ($ str1, $ str2,); // perform the comparison operation
Echo $ result; // output result, 1
/*
The strnatcasecmp () function uses a "natural" algorithm to compare two strings.
In natural algorithms, the number "2" is less than the number "10 ". In computer sorting, "2" is greater than "10" because "2" is greater than "10.
*/
$ Str1 = "hello world"; // defines string 1
$ Str2 = "hello world"; // defines string 2
$ Result = strnatcasecmp ($ str1, $ str2); // perform a comparison operation
Echo $ result; // output result, 0
/*
The strncasecmp () function compares two strings.
This function returns:
0-if the two strings are equal
<0-if string1 is smaller than string2
> 0-if string1 is greater than string2
Syntax
Strncasecmp (string1, string2, length)
*/
$ Str1 = "hello world"; // defines string 1
$ Str2 = "hello world"; // defines string 2
$ Result = strncasemp ($ str1, $ str2, 7); // perform the comparison operation.
Echo $ result; // output result, 0
/*
The strncmp () function compares two strings.
This function returns:
0-if the two strings are equal
<0-if string1 is smaller than string2
> 0-if string1 is greater than string2
Syntax
Strncmp (string1, string2, length)
*/
$ Str1 = "hello world"; // defines string 1
$ Str2 = "hello world"; // defines string 2
$ Result = strncmp ($ str1, $ str2, 7); // perform the comparison operation.
Echo $ result; // output result, 1
/*
The strcoll () function compares two strings.
This function returns:
0-if the two strings are equal
<0-if string1 is smaller than string2
> 0-if string1 is greater than string2
String comparison varies according to local settings. (A <a or a> ).
Syntax
Strcoll (string1, string2)
*/
$ Str1 = "hello world"; // defines string 1
$ Str2 = "hello world"; // defines string 2
$ Result = strcoll ($ str1, $ str2); // compare the result.
Echo $ result; // output result, 1