In PHP, the strncmp () function compares the first two characters of two strings to determine whether they are equal. phpstrncmp_PHP tutorial

Source: Internet
Author: User
In PHP, the strncmp () function compares the methods of the first two characters of the Two Strings, phpstrncmp. In PHP, the strncmp () function is used to compare whether the first two characters of two strings are equal. phpstrncmp this article describes the strncmp () in PHP () the function is used to compare the strncmp () function in PHP to determine whether the first two characters of the two strings are equal. phpstrncmp

This example describes how to use the strncmp () function in PHP to compare the first two characters of two strings. We will share this with you for your reference. The details are as follows:

The strncmp () function in PHP is used to compare two strings (case sensitive) to determine whether the first n characters of the two strings are equal.

The strncmp () function is defined as follows:

Strncmp (string1, string2, length)

Parameter description:

String1 is required. Specifies the first string to be compared.
String2 is required. Specifies the second string to be compared.
Length is required. Specifies the number of characters in each string used in the comparison.

Return value description:

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.

Sample codeAs follows:

<? The php/* strncmp () function compares the first n characters of two strings for equality. ** return value: 0-if the two strings are equal <0-if string1 is less than string2> 0-if string1 is greater than string2 */$ str1 = "welcome to www.jb51.net"; $ str2 = "welcome to www. JB51.NET "; $ str3 =" welcome to php "; echo strncmp ($ str1, $ str2, 2); echo"
"; Echo strncmp ($ str1, $ str3, 2);?>

The running result is as follows:

10

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.