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 less string2
0-If string1 is greater than string2
0-If string1 is greater than string2
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
CaseCopyCodeThe Code is as follows: <? PHP
Echo strncasecmp ("Hello world! "," Hello Earth! ", 6 );
?>
The output of the code above will be:
The above code will output the following results:
0