Just like this, you need to convert two times. Most of the time, we are for the character set conversion when this is the case, such as the determination of the parameters passed in whether Utf-8, the 5 characters of the wording, can be more, such as utf-8,utf-8,utf-8, then we how to do? Strtolower?strupper? No need.
STRNCASECMP ($a, $b, $length) it's ready.
If the return is 0 equal, then how do we judge?
STRNCASECMP ($str, ' Utf-8 ', 5) = = 0 So, the parameter passed in is UTF8, is it convenient?
Just these functions we do not use very often, I see this function is used in the YII framework, when he handled the event, when the first two characters to determine whether on, this is the judgment. And so I learned a trick.
STRNCASECMP Definition and Usage
Definition and usage
The strncasecmp () function compares the strings.
The strncasecmp () function works by comparing the first n characters of a string (case insensitive).
This function returns:
This function will return the following values:
0-if the strings is 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
Grammar
STRNCASECMP (String1,string2,length)
parameter Parameters |
Description Description |
String1 |
Required. Specifies the first string to compare Necessary parameters. Specifies the first string object to participate in the comparison |
string2 |
Required. Specifies the second string to compare Necessary parameters. Specify a second string object to participate in the comparison |
Length |
Required. Specify the number of characters from each string to being used in the comparison Necessary parameters. Specify the number of characters in a parameter comparison in each string |
Tips and Notes
Watch out.
Note:the strncasecmp () is binary safe and case-insensitive.
Note: the STRNCASECMP () function is binary accurate, and it does not differentiate between letter case.
Example
Case
Copy the Code code as follows:
echo strncasecmp ("Hello world!", "Hello earth!", 6);
?>
The output of the code above would be:
The code above will output the following result:
0
The above describes the I can see your smile PHP strncasecmp string comparison tips, including I can look your smile aspects of the content, I hope to be interested in PHP tutorial friends helpful.