Welcome to the Linux community forum and interact with 2 million technical staff to enter the strncasecmp string comparison function in php. usage instructions: we usually use strtolower or strtoupper to convert the string to lower-case or upper-case before determining whether the string is equal. But this requires two conversions. Mostly
Welcome to the Linux community forum and interact with 2 million technical staff> Go To The strncasecmp string comparison function in php. usage instructions: we usually use strtolower or strtoupper to convert the string to lower-case or upper-case before determining whether the string is equal. But this requires two conversions. Mostly
Welcome to the Linux community forum and interact with 2 million technicians>
Usage of strncasecmp string comparison functions in php:
We usually use strtolower or strtoupper to convert the string to lower-case or upper-case before determining whether the string is equal.
But this requires two conversions. Most of the time, we are for character set conversion will be like this, such as determining whether the parameter passed in UTF-8, the five character writing, but more, such as UTF-8, Utf-8, what should we do with UTF-8? Strtolower? Strupper? No ......
Strncasecmp ($ a, $ B, $ length ......
If the return value is 0, it is equal. How can we determine?
Strncasecmp ($ str, 'utf-8', 5) = 0. Then, the input parameter is utf8. Is it convenient?
These functions are not commonly used. I can see that the function is used in yii framework. When processing events and determining whether the first two characters are on, this is the case. I also learned a trick.
Definition and usage
The strncasecmp () function compares the first n characters of a string (Case Insensitive ).
This function returns the following values:
0? If the string is equal
<0? If string1 is smaller than string2
> 0? If string1 is greater than string2
Syntax
Syntax
Strncasecmp (string1, string2, length)
Parameter Description
Required parameter of string1. Specifies the first string object involved in the comparison
Required parameter of string2. Specify the second string object involved in the comparison
Length required parameter. Specify the number of characters for Parameter comparison in each string
Note: The strncasecmp () function is binary accurate and case-insensitive.
Instance
Echo strncasecmp ("Hello world! "," Hello phpzixue.cn! ", 6 );
?>
The result is as follows:
0