Home > Backend Development > PHP Tutorial > i can see your smile PHP strncasecmp string comparison tips

i can see your smile PHP strncasecmp string comparison tips

WBOY
Release: 2016-07-29 08:44:09
Original
1094 people have browsed it

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
Tips and Notes
Note: The strncasecmp() is binary safe and case-insensitive.
Note: The strncasecmp() function is binary accurate, and it Letters are not case sensitive.
Example
Case

Copy code 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
The above introduces the tips of i can see your smile PHP strncasecmp string comparison, including the content of i can see your smile. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template