Home > Backend Development > PHP Tutorial > PHP version judgment version_compare() function, phpversion_compare_PHP tutorial

PHP version judgment version_compare() function, phpversion_compare_PHP tutorial

WBOY
Release: 2016-07-13 10:13:17
Original
1804 people have browsed it

PHP version judgment version_compare() function, phpversion_compare

Brief search in Du Niang to determine whether the current PHP version is higher than a certain version, or lower than a certain version A version of the method

The displayed results are basically the same. Well, if I hadn’t forgotten the version_compare() function, I wouldn’t have gone to Du Niang and decided to look for the previous code

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

version_compare() is used to compare two "PHP normalized" version number strings. This is helpful for writing programs that are only compatible with certain versions of PHP

mixed version_compare ( string $version1 , string $version2 [, string $operator ] )

Return to hybrid

string $version1 - version 1 required

string $version2 - version 2 required

string $operator - understand it as an operator. Optional

That is, <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <> and ne.

If the third parameter is specified, boolean will be returned. If the third parameter is not specified, the following three situations will be returned:

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

When the first version is equal to the second version, return 0

When the first version is smaller than the second version, return 1

<?php
header('content-type:text/html;charset=utf-8');
/**
 * 判断php的版本是否在5.3.0以上
 */

echo '<pre class="brush:php;toolbar:false">';
 
//本人使用的版本为  5.2.17
echo 'PHP的当前版本为 '.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 '您的PHP版本大于5.3.0,当前版本为 '.PHP_VERSION;

}else{

	echo '您的PHP版本小于5.3.0,当前版本为 '.PHP_VERSION;

}
Copy after login

The results are as follows:

PHP的当前版本为 <span>5.2</span>.<span>17</span><span>
int(</span><span>1</span><span>)
bool(</span><span>false</span><span>)
bool(</span><span>false</span><span>)
您的PHP版本小于5.</span><span>3.0</span>,当前版本为 <span>5.2</span>.<span>17</span>
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/916825.htmlTechArticlePHP version judgment version_compare() function, phpversion_compare is simply searched in Du Niang to judge the current PHP version Is it higher than a certain version, or lower than a certain version...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template