Just do this and you need to convert it twice. Most of the time, we do this when we are converting character sets, such as judging whether the parameters passed in are utf-8. There are many ways to write these 5 characters, such as UTF-8, Utf-8, utf-8, etc. , then what should we do? strtolower? strupper? No need. .
strncasecmp($a,$b,$length) will do. .
If the return value is 0, it means they are equal, so how do we judge?
strncasecmp($str,'utf-8',5) == 0 Then, the parameter passed in is utf8. Is it convenient?
It’s just that we don’t usually use these functions. I saw the usage of this function in yii framework. When it processes events, it determines whether the first two characters are on. This is how it is judged. I also learned a trick from this.
strncasecmp Definition and Usage
Definition and Usage
The strncasecmp() function compares two strings.
The strncasecmp() function compares the first n characters of the string (case insensitive).
This function returns:
This function will return the following values:
0 - if the two strings are equal
0 - if the strings are equal
<0 - if string1 is less than string2
<0 - if string1 is less than string2
>0 - if string1 is greater than string2
>0 - if string1 is greater than string2
Syntax
Syntax
strncasecmp(string1,string2,length)
Parameter parameter | Description |
---|---|
string1 | Required. Specifies the first string to compare Required parameters. Specifies the first string object to be compared |
string2 | Required. Specifies the second string to compare Required parameters. Specify the second string object participating 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 argument comparison in each string |
Copy code The code is as follows:
echo strncasecmp("Hello world!","hello earth!",6);
?>