strcmp () and strcasecmp () function strings in PHP comparison usage analysis, strcmpstrcasecmp_php tutorial

Source: Internet
Author: User

strcmp () and strcasecmp () function strings in PHP compare usage analysis, strcmpstrcasecmp


The examples in this article describe the use of strcmp () and strcasecmp () function strings in PHP. Share to everyone for your reference, as follows:

One, PHP strcmp () function is used to compare two strings (case-sensitive), which is defined as follows:

strcmp (STRING1,STRING2)

Parameter description:

String1 required. Specifies the first string to compare.
string2 required. Specifies a second string to compare.

PS: Thestrcmp () function is similar to the strncmp () function, unlike the STRNCMP () can specify the number of characters each string is used to compare.

Second, PHP strcasecmp () function compares two strings (case-insensitive), which is defined as follows:

STRCASECMP (STRING1,STRING2)

Parameter description:

String1 required. Specifies the first string to compare.
string2 required. Specifies a second string to compare.

PS: Thestrcasecmp () function is similar to the strncasecmp () function, unlike the STRNCASECMP () can specify the number of characters each string is used to compare.

Example code:

<?php $str 1 = "Home for the guests"; $str 2 = "Home for the guests"; $str 3= "Www.jb51.net"; $str 4= "WWW.JB51.NET"; Echo strcmp ($str 1, $str 2);//Two strings equal echo "
"; Echo strcmp ($str 3, $str 4);//Note that the function is case-sensitive, echo "
"; Echo strcasecmp ($str 3, $str 4);//The function is case-insensitive?>

The results of the operation are as follows:

010

Add: Questions about return values

For comparison of parameter string1 and string2:

If two strings are equal, the return value is 0
If string1 is less than string2, the return value is less than 0
If string1 is greater than string2, the return value is greater than 0

I hope this article is helpful to you in PHP programming.

Articles you may be interested in:

    • How the Substr_count () function Gets the number of substrings in PHP
    • PHP uses the STRSTR () function to obtain a method for all characters after a specified string
    • PHP strncmp () function compares the first 2 characters of a two string method
    • STRNATCMP () function "Natural sorting algorithm" in PHP for string comparison usage analysis (compare strcmp function)
    • Analysis of substr function string interception usage in PHP
    • PHP uses Trim function to remove left and right spaces and special character instances
    • PHP encapsulated string encryption and decryption function
    • The most accurate PHP intercept string length function
    • What to do if you use substr () in PHP to intercept strings in Chinese characters.
    • Summary of examples of PHP common string manipulation functions

http://www.bkjia.com/PHPjc/1089579.html www.bkjia.com true http://www.bkjia.com/PHPjc/1089579.html techarticle php strcmp () and strcasecmp () function string comparison usage analysis, STRCMPSTRCASECMP This example describes the strcmp () and strcasecmp () function string comparison usage in PHP. Share for the big ...

  • 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.