I can see your smile PHP strncasecmp string comparison tips

Source: Internet
Author: User
Tags first string
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.