Summary of common string processing in PHP Development

Source: Internet
Author: User
Comparing strings in PHP can be achieved by comparing the size of two strings in two ways: Using operators to compare and using functions to compare the size of two strings using operators: when comparing two strings in PHP, the easiest way is to use the double equal sign operator (). Use a function to compare the size of a string: in PHP, extract

Comparing strings in PHP can be achieved by comparing the size of two strings in two ways: using the = Operator to compare and using a function to compare the size of two strings using the = Operator: when comparing two strings in PHP, the easiest way is to use the equal sign operator (= ). Use a function to compare the size of a string: in PHP, extract

Comparison string

In PHP, comparing the size of two strings can be achieved in two ways: using the "=" operator to compare and using functions

Use the "=" operator to compare the size of two strings: when comparing two strings in PHP, the easiest way is to use the equal sign operator (= ).

Use the function to compare the string size: The strcmp () function provided in PHP can more accurately compare the size of the two strings. The syntax format is as follows: int strcmp (string $ str1, string $ str2) the parameters involved in the preceding syntax are described as follows: str1 specifies the string 1 to be compared and str2 specifies the string 2 to be compared. The strcmp signature is used to ensure that the two strings match completely and return the comparison result in the form of an integer. The return values of this function include the following three types. 0: The two strings are equal. When the value is less than 0, the first string is smaller than the subsequent string. If the return value is greater than zero, it indicates that, the preceding string is greater than the following string.

In addition to the strcmp () function, PHP also provides some similar comparison functions. For example, the strncmp () function can select the length (number of characters) of the string to be compared ), the syntax format is as follows: int strcmp (string $ str1, string $ str2, int $ len) the preceding parameter description str1: Specifies the first string to be compared, str2: specify the second string to be compared len: specify the number of characters each string uses for comparison.

When comparing strings, you can use strcasemp () and strncasemp () functions to ignore case sensitivity, these two functions are used exactly the same as the case-sensitive functions. The syntax formats of strcasecmp () and strncasecmp () functions are as follows:

Int strcasecmp (string $ str1, string $ str2)

Int strncasecmp (string $ str1, string $ str2, int $ len)

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.