PHP code example of vierbergenlars / php-semver

1. Go to this page and download the library: Download vierbergenlars/php-semver 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/ */

    

vierbergenlars / php-semver example snippets




use vierbergenlars\SemVer\version;
use vierbergenlars\SemVer\expression;
use vierbergenlars\SemVer\SemVerException;

// Check if a version is valid
$semver = new version('1.2.3');
$semver = new version('a.b.c'); //SemVerException thrown

//Get a clean version string
$semver = new version('=v1.2.3');
$semver->getVersion(); //'1.2.3'

//Check if a version satisfies a range
$semver = new version('1.2.3');
$semver->satisfies(new expression('1.x || >=2.5.0 || 5.0.0 - 7.2.3')); //true
# OR
$range = new expression('1.x || >=2.5.0 || 5.0.0 - 7.2.3');
$range->satisfiedBy(new version('1.2.3')); //true

//Compare two versions
version::gt('1.2.3', '9.8.7'); //false
version::lt('1.2.3', '9.8.7'); //true