PHP version Judge Version_compare () function

Source: Internet
Author: User

Original http://www.cnphp6.com/archives/63604

This is how the Version_compare () function is described in the PHP manual:

Version_compare () is used to compare the version number string of two "php normalization. This is useful for writing programs that are compatible with only certain versions of PHP

Mixed Version_compare (String $version 1, String $version 2 [, String $operator])

Back to Mixed type

String $version version 1 required

String $version 2– version 2 must be filled in

String $operator – understood as an operator bar optional

Namely <, LT, <=, le, >, GT, >=, ge, = =, =, eq,!=, <> and NE.

If the third argument is specified, a Boolean is returned, and if the third argument is not specified, there are three of the following:

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 higher than the second version

<?php
Header (' Content-type:text/html;charset=utf-8 ');
/**
 * To determine whether PHP version is above 5.3.0

/echo ' <pre> ';
 
I use the version of  5.2.17
Echo ' PHP for the current version of '. 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:

The current version of PHP is 5.2.17
int (1) bool (FALSE) bool (false
)
your PHP version is less than 5.3.0, the current version is 5.2.17

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.