1. String comparisons by Byte:
The strcmp () and strcasecmp () functions are used to compare two strings by byte.
Syntax format:
int strcmp (string str1,string str2)
int strcasecmp (string str1,string str2)
If STR1=STR2, the return value is 0; if STR1>STR2, the return value >0; if STR1<STR2, the return value is less than 0
The difference between the two functions is that strcmp () distinguishes the case of the characters, while STRCASECMP () does not distinguish between the case of characters
2, according to natural sorting method for string comparison: strmatcmp () function
Grammar:
int strnatcmp (string str1,string str2)
Returns 0 if the string is equal, and if STR1>STR2, the return value is greater than 0; if STR1<STR2, the return value is less than 0
3. Specify a comparison from the position of the source string: strncmp () function
Grammar:
int strncmp (string str1,string str2,int len)
Description
STR1: Specifies the first string to participate in the comparison
STR2: Specifies the second string to participate in the comparison
Len: Specifies the number of characters involved in the comparison in each string
If the string is equal, return 0 if STR1>STR2, return value >0; if STR1<STR2, return value <0
Example: Compare the first three characters of two strings for equality
<?php
$a = "www.bianceng.cn";
$b = "www.bianceng.com";
Echo strncmp ($a, $b, 3);
?>