How does PHP compare the size of a string?

Source: Internet
Author: User
Tags php compare
In WEB project development, we often need to determine the size between two or more strings. However, we can't determine the size of the Two Strings, so how can we determine the size of two or more strings? this article will show you how to compare the size of strings? In WEB project development, we often need to determine the size between two or more strings. However, we can't determine the size of the Two Strings, how can we determine the size of two or more strings, How to compare the string size?

First, we should first learn two functions.Strcmp () and strcasecmp () functions

Both functions are used to compare the sizes of two strings. their syntax is as follows:

strcmp(str1,str2)
strcasecmp(str1,str2)

These two functions compare the size of two strings based on the (ASCII code value). if str1> str2, 1 is returned; if str1

Application instance

The following uses the strcasecmp () and strcmp () functions to compare the string size.

The code is as follows:

    
     String case-sensitive conversion
 String '". $ str1."'> string '". $ str2 ."'

";} If ($ result = 0) {echo"

String '". $ str1."' = String '". $ str2 ."'

";} If ($ result =-1) {echo"

String '". $ str1."' <string '". $ str2 ."'

";}}?>

The code execution result is as follows:

1. how does php perform case-insensitive conversion on strings?

2. php Video Tutorial: php1.cn Dugu Jiuyu (4)-php video tutorial

3. php string topic

The above is how PHP compares the string size? For more information, see other related articles in the first PHP community!

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.