It seems that most of the time, we use strtolower or strtoupper to compare strings, and then judge whether they are equal. In this case, the conversion is required twice. 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.
Strncasecmp Definition and Usage
Definition and usage
The strncasecmp () function compares two strings.
The strncasecmp () function compares the first n characters of a string (case insensitive ).
This function returns:
This function returns the following values:
0-if the two strings are equal
0-if the string is equal
<0-if string1 is less than string2
<0-if string1 is smaller than string2
> 0-if string1 is greater than string2
> 0-if string1 is greater than string2
Syntax
Syntax
Strncasecmp (string1, string2, length)
| Parameter parameters |
Description |
| String1 |
Required. Specifies the first string to compare
Required parameter. Specifies the first string object involved in the comparison |
| String2 |
Required. Specifies the second string to compare
Required parameter. Specify the second string object involved in the comparison |
| Length |
Required. Specify the number of characters from each string to be used in the comparison
Required parameter. Specify the number of characters for parameter comparison in each string |
Tips and Notes
Notes
Note: The strncasecmp () is binary safe and case-insensitive.
Note: The strncasecmp () function is binary accurate and case-insensitive.
Example
Case
The code is as follows:
Echo strncasecmp ("Hello world! "," Hello earth! ", 6 );
?>
The output of the code above will be:
The above code will output the following results:
0