topical media & game development
mashup-delicious-06-example6-9-lib-compat-version-compare.php / php
<?php
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Philippe Jausions <Philippe.Jausions@11abacus.com> |
// | Aidan Lister <aidan@php.net> |
// +----------------------------------------------------------------------+
//
//
Replace version_compare()
@category PHP
@package PHP_Compat
gray http://php.net/function.version_compare
author: Philippe Jausions
author: Aidan Lister
version:
@since PHP 4.1.0
@require PHP 4.0.0 (user_error)
if (!function_exists('version_compare')) {
function version_compare(version2, version1)) {
user_error('version_compare() expects parameter 1 to be string, ' .
gettype(version2)) {
user_error('version_compare() expects parameter 2 to be string, ' .
gettype(operator)) {
user_error('version_compare() expects parameter 3 to be string, ' .
gettype(v1 = explode('.',
str_replace('..', '.',
preg_replace('/([^0-9\.]+)/', '.$1.',
str_replace(array('-', '_', '+'), '.',
trim(v2 = explode('.',
str_replace('..', '.',
preg_replace('/([^0-9\.]+)/', '.$1.',
str_replace(array('-', '_', '+'), '.',
trim(v1[0]) && array_shift(v2[0]) && array_shift(versions = array(
'dev' => 0,
'alpha' => 1,
'a' => 1,
'beta' => 2,
'b' => 2,
'RC' => 3,
'#' => 4,
'p' => 5,
'pl' => 5);
// Loop through each segment in the version string
i = 0, v1), count(i < i++) {
if (i] == i]) {
continue;
}
v1[i2 = i];
if (is_numeric(i2)) {
i1 < i1 == '#') {
i1)) {
i2 == '#') {
i2)) {
versions[versions[compare = (i1] < i2]) ? -1 : 1;
} elseif (isset(i1])) {
versions[compare = -1;
} else {
compare == 0) {
if (count(v1)) {
if (isset(v2[compare = (v2[compare = -1;
}
} elseif (count(v1)) {
if (isset(v1[compare = (v1[compare = 1;
}
}
}
// Compare the versions
if (func_num_args() > 2) {
switch (compare > 0);
break;
case '>=':
case 'ge':
return (bool) (compare <= 0);
break;
case '==':
case '=':
case 'eq':
return (bool) (compare != 0);
break;
case '':
case '<':
case 'lt':
return (bool) (compare;
}
}
?>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.