Comparison of strcmp and strcasecmp function strings in PHP

Source: Internet
Author: User
: This article mainly introduces the usage and analysis of strcmp and strcasecmp function strings in PHP. if you are interested in the PHP Tutorial, refer to it. This document describes how to compare strcmp () and strcasecmp () functions in PHP. We will share this with you for your reference. The details are as follows:

1. the strcmp () function in PHP is used to compare two strings (case sensitive). its definition is as follows:

Strcmp (string1, string2)

Parameter description:

String1 is required. Specifies the first string to be compared.
String2 is required. Specifies the second string to be compared.

PS: The strcmp () function is similar to the strncmp () function. The difference is that strncmp () can specify the number of characters that each string uses for comparison.

2. the strcasecmp () function in PHP compares two strings (case-insensitive). its definition is as follows:

Strcasecmp (string1, string2)

Parameter description:

String1 is required. Specifies the first string to be compared.
String2 is required. Specifies the second string to be compared.

PS: The strcasecmp () function is similar to the strncasecmp () function. The difference is that strncasecmp () can specify the number of characters that each string uses for comparison.

Sample code:

<? Php $ str1 = ""; $ str2 = ""; $ str3 = "www.jb51.net"; $ str4 = "WWW. JB51.NET "; echo strcmp ($ str1, $ str2); // two strings are equal to echo"
"; Echo strcmp ($ str3, $ str4); // note that this function is case sensitive echo"
"; Echo strcasecmp ($ str3, $ str4); // is this function case insensitive?>

The running result is as follows:

010

Supplement: Questions about return values

Comparison between string1 and string2:

If the 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 will help you with PHP programming.

The above introduces the comparative usage analysis of strcmp and strcasecmp function strings in PHP, including some content, and hope to help those who are interested in PHP tutorials.

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.