Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

version_compare(3) [php man page]

VERSION_COMPARE(3)							 1							VERSION_COMPARE(3)

version_compare - Compares two ";PHP-standardized" version number strings

SYNOPSIS
mixed version_compare (string $version1, string $version2, [string $operator]) DESCRIPTION
version_compare(3) compares two "PHP-standardized" version number strings. The function first replaces _, - and + with a dot . in the version strings and also inserts dots . before and after any non number so that for example '4.3.2RC1' becomes '4.3.2.RC.1'. Then it compares the parts starting from left to right. If a part contains special version strings these are handled in the following order: any string not found in this list < dev < alpha = a < beta = b < RC = rc < # < pl = p. This way not only versions with different levels like '4.1' and '4.1.2' can be compared but also any PHP specific version containing devel- opment state. PARAMETERS
o $version1 - First version number. o $version2 - Second version number. o $operator - If the third optional $operator argument is specified, test for a particular relationship. The possible operators are: <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne respectively. This parameter is case-sensitive, values should be lowercase. RETURN VALUES
By default, version_compare(3) returns -1 if the first version is lower than the second, 0 if they are equal, and 1 if the second is lower. When using the optional $operator argument, the function will return TRUE if the relationship is the one specified by the operator, FALSE otherwise. EXAMPLES
The examples below use the PHP_VERSION constant, because it contains the value of the PHP version that is executing the code. Example #1 version_compare(3) examples <?php if (version_compare(PHP_VERSION, '6.0.0') >= 0) { echo 'I am at least PHP version 6.0.0, my version: ' . PHP_VERSION . " "; } if (version_compare(PHP_VERSION, '5.3.0') >= 0) { echo 'I am at least PHP version 5.3.0, my version: ' . PHP_VERSION . " "; } if (version_compare(PHP_VERSION, '5.0.0', '>=')) { echo 'I am using PHP 5, my version: ' . PHP_VERSION . " "; } if (version_compare(PHP_VERSION, '5.0.0', '<')) { echo 'I am using PHP 4, my version: ' . PHP_VERSION . " "; } ?> NOTES
Note The PHP_VERSION constant holds current PHP version. Note Note that pre-release versions, such as 5.3.0-dev, are considered lower than their final release counterparts (like 5.3.0). Note Special version strings such as alpha and beta are case sensitive. Version strings from arbitrary sources that do not adhere to the PHP standard may need to be lowercased via strtolower(3) before calling version_compare(3). SEE ALSO
phpversion(3), php_uname(3), function_exists(3). PHP Documentation Group VERSION_COMPARE(3)

Check Out this Related Man Page

Dpkg::Version(3)						   libdpkg-perl 						  Dpkg::Version(3)

NAME
Dpkg::Version - handling and comparing dpkg-style version numbers DESCRIPTION
The Dpkg::Version module provides pure-Perl routines to compare dpkg-style version numbers (as used in Debian packages) and also an object oriented interface overriding perl operators to do the right thing when you compare Dpkg::Version object between them. OBJECT INTERFACE
my $v = Dpkg::Version->new($version, %opts) Create a new Dpkg::Version object corresponding to the version indicated in the string (scalar) $version. By default it will accepts any string and consider it as a valid version. If you pass the option "check => 1", it will return undef if the version is invalid (see version_check for details). You can always call $v->is_valid() later on to verify that the version is valid. boolean evaluation When the Dpkg::Version object is used in a boolean evaluation (for example in "if ($v)" or "$v || 'default'") it returns its string representation if the version stored is valid ($v->is_valid()) and undef otherwise. $v->is_valid() Returns true if the version is valid, false otherwise. $v->epoch(), $v->version(), $v->revision() Returns the corresponding part of the full version string. $v1 <=> $v2, $v1 < $v2, $v1 <= $v2, $v1 > $v2, $v1 >= $v2 Numerical comparison of various versions numbers. One of the two operands needs to be a Dpkg::Version, the other one can be anything provided that its string representation is a version number. "$v", $v->as_string() Returns the string representation of the version number. FUNCTIONS
All the functions are exported by default. version_compare($a, $b) Returns -1 if $a is earlier than $b, 0 if they are equal and 1 if $a is later than $b. If $a or $b are not valid version numbers, it dies with an error. version_compare_relation($a, $rel, $b) Returns the result (0 or 1) of the given comparison operation. This function is implemented on top of version_compare(). Allowed values for $rel are the exported constants REL_GT, REL_GE, REL_EQ, REL_LE, REL_LT. Use version_normalize_relation() if you have an input string containing the operator. my $rel = version_normalize_relation($rel_string) Returns the normalized constant of the relation $rel (a value among REL_GT, REL_GE, REL_EQ, REL_LE and REL_LT). Supported relations names in input are: "gt", "ge", "eq", "le", "lt", ">>", ">=", "=", "<=", "<<". ">" and "<" are also supported but should not be used as they are obsolete aliases of ">=" and "<=". version_compare_string($a, $b) String comparison function used for comparing non-numerical parts of version numbers. Returns -1 if $a is earlier than $b, 0 if they are equal and 1 if $a is later than $b. The "~" character always sort lower than anything else. Digits sort lower than non-digits. Among remaining characters alphabetic characters (A-Za-z) sort lower than the other ones. Within each range, the ASCII decimal value of the character is used to sort between characters. version_compare_part($a, $b) Compare two corresponding sub-parts of a version number (either upstream version or debian revision). Each parameter is split by version_split_digits() and resulting items are compared together.in digits and non-digits items that are compared together. As soon as a difference happens, it returns -1 if $a is earlier than $b, 0 if they are equal and 1 if $a is later than $b. my @items = version_split_digits($version) Splits a string in items that are each entirely composed either of digits or of non-digits. For instance for "1.024~beta1+svn234" it would return ("1", ".", "024", "~beta", "1", "+svn", "234"). my ($ok, $msg) = version_check($version) my $ok = version_check($version) Checks the validity of $version as a version number. Returns 1 in $ok if the version is valid, 0 otherwise. In the latter case, $msg contains a description of the problem with the $version scalar. AUTHOR
Don Armstrong <don@donarmstrong.com>, Colin Watson <cjwatson@debian.org> and Raphael Hertzog <hertzog@debian.org>, based on the implementation in "dpkg/lib/vercmp.c" by Ian Jackson and others. 1.16.0.3 2012-04-17 Dpkg::Version(3)
Man Page