PHP version Judge Version_compare () function, phpversion_compare_php tutorial

Source: Internet
Author: User

PHP version Judge Version_compare () function, Phpversion_compare


In the degree Niang simple to find the next, to determine whether the current version of PHP is higher than a version, or lower than a version of the method

The results are basically the same, okay, if I didn't forget version_compare () This function I'm not going to look for the Niang, determined to find the previous code

The PHP manual describes the Version_compare () function in the following way:

Version_compare () is used to compare two "php normalized" version number strings. This is useful for writing programs that can only be compatible with certain versions of PHP

Mixed Version_compare ( string $version1 , string $version2 [, string $operator ])

Back to Mixed type

String $version 1-Version 1 required

String $version 2-Version 2 required

String $operator-understood as operator bar optional

i.e. <,lt,<=, le,>, gt,>=, ge, = =, =,eq,! =,<> and ne.

If the third argument is specified, a Boolean is returned, and if no third parameter is specified, the following three kinds of cases are returned:

When the first version is lower than the second version return-1

Return 0 when the first version equals the second version

Return 1 when the first version is less than the second version

 
  '; I am using the version  5.2.17echo ' php current version is '. Php_version. " \ n "; Var_dump (Version_compare (php_version, ' 5.2.0 ')); Var_dump (Version_compare (php_version, ' 5.2.0 ', ' = ')); var_dump (Version_compare (php_version, ' 5.3.0 ', ' ge ')), if (Version_compare (php_version, ' 5.3.0 ', ' ge ')) {echo ' your PHP version is greater than 5.3.0, The current version is '. Php_version;} Else{echo ' Your PHP version is less than 5.3.0, the current version is '. Php_version;}

The results are as follows:

5.2.  - Int (1) bool(False) bool (false) your PHP version is less than 5. 3.0 5.2.  -

http://www.bkjia.com/PHPjc/916825.html www.bkjia.com true http://www.bkjia.com/PHPjc/916825.html techarticle PHP version to determine the Version_compare () function, phpversion_compare in the degree Niang simple to find the next, to determine whether the current version of PHP is higher than a version, or less than a version of the method ...

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