Comparison and usage analysis of strcmp () and strcasecmp () function strings in PHP, strcmpstrcasecmp_PHP tutorial

Source: Internet
Author: User
Comparison and usage analysis of strcmp () and strcasecmp () function strings in PHP, strcmpstrcasecmp. Comparison and usage analysis of strcmp () and strcasecmp () function strings in PHP. This document describes the comparison and usage of strcmp () and strcasecmp () function strings in PHP. We will share with you the usage analysis of strcmp () and strcasecmp () function strings in PHP, strcmpstrcasecmp

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:

I. strcmp () function in PHP is used to compare two strings (case sensitive), Which is defined 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 each string uses for comparison.

2. the strcasecmp () function in PHP compares two strings (case insensitive), Which is defined 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.

Articles you may be interested in:
  • How to use the substr_count () function in PHP to obtain the occurrence times of a substring
  • PHP uses the strstr () function to obtain all characters after a specified string
  • The strncmp () function in PHP compares the first two characters of two strings to determine whether they are equal.
  • In PHP, the strnatcmp () function "natural sorting algorithm" is used to analyze the usage of string comparison (compared with the strcmp function)
  • Analysis on the use of substr function string truncation in PHP
  • PHP uses the trim function to remove leading and trailing spaces of strings and special character instances
  • PHP-encapsulated string encryption and decryption functions
  • The most accurate php string length truncation function
  • PHP uses substr () to intercept strings. what should I do if Chinese characters are garbled?
  • Summary of common PHP string operation function instances

Comparison and usage analysis of strcasecmp () and strcasecmp function strings. This document describes the comparison and usage of strcmp () and strcasecmp () function strings in PHP. Share it with you...

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.