It just needs to be converted two times. Most of the time, we are on the character set conversion time will be so, such as judging the parameters passed in whether Utf-8, the 5 characters of the writing, but more, such as utf-8,utf-8,utf-8, then how do we do? Strtolower?strupper? No need.
STRNCASECMP ($a, $b, $length) is OK.
If the return is equal to 0, how do we judge it?
STRNCASECMP ($str, ' Utf-8 ', 5) = 0 So, the incoming parameter is UTF8, is it convenient?
It's just that we don't use them very often, and I see that this function is used in the YII framework, and that's when he's dealing with an event, judging whether the first two characters are on. And so I learned a trick.
STRNCASECMP Definition and Usage
Definitions and usage
The strncasecmp () function compares two strings.
The strncasecmp () function is to compare the first n characters of a string (not case sensitive).
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 than string2
>0-if string1 is greater than string2
>0– if string1 is greater than string2
Syntax
Grammar
STRNCASECMP (String1,string2,length)
parameter Parameters |
Description Description |
String1 |
Required. Specifies the "a" to compare Necessary parameters. Specifies the first string object to participate in the comparison |
string2 |
Required. Specifies the second string to compare Necessary parameters. Specifies the second string object to participate in the comparison |
Length |
Required. Specify the number of characters from each string to is used in the comparison Necessary parameters. Specify the number of characters in each string to compare the parameters |
Tips and Notes
Pay attention.
Note:the strncasecmp () is binary safe and case-insensitive.
Note: the STRNCASECMP () function is binary precise and does not differentiate between uppercase and lowercase letters.
Example
Case
Copy CodeThe code is as follows:
<?php
echo strncasecmp ("Hello world!", "Hello earth!", 6);
?>
The output of the code above would be:
The above code will output the following result:
0