PHP determines the length of the two methods of string is very useful, the string is very useful _php tutorial

Source: Internet
Author: User

PHP two methods to determine the length of the string is very useful, the string is very useful


PHP program in the length of the string to judge, you can use strlen.

Method One:

$str = ' aaaaaa '; if (strlen ($STR) > 6) {echo "string greater than 6";}

Method Two:

if (Isset ($str {6}) {}

The two methods above, the second is more efficient.

In PHP, all of the variables are saved with a structure-zval, strlen although the Len is directly obtained, but there is still a function call, and isset is the syntax structure of PHP, so faster! Therefore, the second method can be used when judging whether a string is greater than or less than the number of characters.

http://www.bkjia.com/PHPjc/1057471.html www.bkjia.com true http://www.bkjia.com/PHPjc/1057471.html techarticle PHP determines the length of the two methods of string is very useful, the string is useful in PHP program string length, you can use strlen. Method One: $str = ' aaaaaa '; if (strlen ($STR) 6) {e ...

  • 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.