Compares two version number strings based on Semantic Versioning 2.0.0
Using Composer to add the package to your project's dependencies:
$ composer require questocat/version-comparator
$semVerManager = new SemVerManager();
$semVerManager->compare('2.9.0', '2.9.6', '<'); // true
$semVerManager->compare('5.1.0', '5.1.0-alpha', '>'); // true
$semVerManager->compare('2.0.1-alpha.2', '2.0.1-alpha.1', '<'); // false
$semVerManager->compare('2.0.1-alpha.2', '2.0.1-alpha.1', '>'); // true
$semVerManager->compare('2.0.1-alpha.2', '2.0.1-alpha.1', '!='); // true
$semVerManager->compare('1.0.0-alpha.1', '1.0.0-alpha.beta', '<'); // true
$semVerManager->compare('2.0.1-alpha-abc.2', '2.0.1-alpha-abc.1', '>'); // true
$semVerManager->compare('1.0.0-alpha', '1.0.0-beta', '<'); // true
$semVerManager->compare('0.0.0+0', '0.0.0+1', '='); // true
$semVerManager->compare('1.0.0-alpha+001', '1.0.0+20130313144700', '<'); // true
$semVerManager->compare('1.0.0-rc.1+build.1', '1.0.0-rc.1', '<'); // false
$semVerManager->compare('1.0.0-rc.1+build.1', '1.0.0-rc.1', '='); // true
$semVerManager->compare('1.0.0-rc.2+build.1', '1.0.0-rc.1', '<'); // fasle
$semVerManager->compare('1.0.0-rc.2+build.1', '1.0.0-rc.1', '>='); // true
$semVerManager->compare('1.0.0-alpha', '1.0.0-alpha.1', '<');
$semVerManager->compare('1.0.0-alpha.1', '1.0.0-alpha.beta', '<');
$semVerManager->compare('1.0.0-alpha.beta', '1.0.0-beta', '<');
$semVerManager->compare('1.0.0-beta', '1.0.0-beta.2', '<');
$semVerManager->compare('1.0.0-beta.2', '1.0.0-beta.11', '<');
$semVerManager->compare('1.0.0-beta.11', '1.0.0-rc.1', '<');
$semVerManager->compare('1.0.0-rc.1', '1.0.0', '<');
1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0- rc.1 < 1.0.0
$semVerManager = new SemVerManager('2.9.0');
$semVerManager->compareTo('2.9.6', '<'); // true
$semVerManager->compareTo('2.8.9', '>'); // true
$semVerManager->compareTo('2.8.9-alpha', '>'); // true
Licensed under the MIT license.