1. Go to this page and download the library: Download horde/version library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
horde / version example snippets
use Horde\Version\SemVerV2Version;
use Horde\Version\RelaxedSemanticVersion;
// Strict SemVer 2.0
$version = new SemVerV2Version('1.0.0');
$version = new SemVerV2Version('1.0.0-alpha.1+build.123');
// Relaxed format (prefixes, no hyphen, missing patch)
$version = new RelaxedSemanticVersion('v1.0.0');
$version = new RelaxedSemanticVersion('1.0'); // → 1.0.0
$version = new RelaxedSemanticVersion('1.0.0alpha1'); // → 1.0.0-alpha1
// Access components
echo $version->major; // 1
echo $version->minor; // 0
echo $version->patch; // 0
echo $version->preRelease; // 'alpha1'
echo $version->buildInfo; // ''
use Horde\Version\SemVerV2Comparison;
$comparison = new SemVerV2Comparison();
$result = $comparison->compare(
new SemVerV2Version('1.0.0'),
new SemVerV2Version('2.0.0')
); // -1 (first < second)
// Or use helper methods
$v1 = new SemVerV2Version('1.0.0');
$v2 = new SemVerV2Version('2.0.0');
$v1->isLessThan($v2); // true
$v2->isGreaterThan($v1); // true
$v1->equals($v1); // true
use Horde\Version\ConstraintParser;
$parser = new ConstraintParser();
// Exact match
$constraint = $parser->parse('1.0.0');
$constraint->isSatisfiedBy($version); // true if version == 1.0.0
// Comparison operators
$constraint = $parser->parse('>=1.0.0');
$constraint = $parser->parse('<2.0.0');
$constraint = $parser->parse('!=1.5.0');
// Caret (^) - Allow changes that don't modify left-most non-zero
$constraint = $parser->parse('^1.2.3'); // >=1.2.3 <2.0.0
$constraint = $parser->parse('^0.2.3'); // >=0.2.3 <0.3.0
$constraint = $parser->parse('^0.0.3'); // =0.0.3
// Tilde (~) - Allow patch-level changes
$constraint = $parser->parse('~1.2.3'); // >=1.2.3 <1.3.0
$constraint = $parser->parse('~1.2'); // >=1.2.0 <2.0.0
// Wildcard
$constraint = $parser->parse('1.0.*'); // >=1.0.0 <1.1.0
$constraint = $parser->parse('1.*'); // >=1.0.0 <2.0.0
// Range
$constraint = $parser->parse('1.0.0 - 2.0.0');
// AND (space-separated)
$constraint = $parser->parse('>=1.0.0 <2.0.0');
// OR (||)
$constraint = $parser->parse('^1.0 || ^2.0');
// Check if version satisfies constraint
if ($constraint->isSatisfiedBy($version)) {
echo "Version is compatible!";
}