PHP strncmp () function compares the first n characters of two strings for equality,
The function of strncmp () function, parameter usage and use skill are analyzed.
Share to everyone for your reference, as follows:
The strncmp () function in PHP is used to compare two strings (case-sensitive) to determine whether the first n characters of the two strings are equal.
The strncmp () function is defined as follows:
STRNCMP (String1,string2,length)
Parameter description:
String1 required. Specifies the first string to compare.
string2 required. Specifies a second string to compare.
Length required. Specifies the number of characters for each string used in the comparison.
Return Value Description:
If two strings are equal, the return value is 0
If string1 is less than string2, the return value is less than 0
If string1 is greater than string2, the return value is greater than 0
The sample code is as follows:
0-if string1 is greater than string2 */$str 1= "Welcome to Www.jb51.net"; $str 2= "WELCOME to WWW.JB51.NET"; $str 3= "Welcome to PHP"; Echo strncmp ($str 1, $str 2,2); echo "
"; Echo strncmp ($str 1, $str 3,2);? >
The results of the operation are as follows:
10
I hope this article is helpful to you in PHP programming.