Jeffrey L. Roberts Jeffrey L. Roberts - 2 years ago 89
PHP Question

PHP Functions to Increment Classic Software Version Numbers?

I am looking for PHP functions that can increment classic software version numbers...



$a_version_number = '3.1.2';

$c = version_increment($a_version_number);
echo 'Next Version: ' . $c . "\n";

Any ideas on where I can find functions that would do what I am looking to do?

Answer Source

Here is a single function that will do both. If the second argument is a positive number, it will increment. If it's a negative number, it will decrement:

function version_update($i, $inc_dec){
    $a = explode('.', $i);
    if($inc_dec > 0){
    } elseif ($inc_dec < 0){
    return implode('.', $a); 

$b = version_update($a_version_number, -1);
echo 'Previous Version: ' . $b . "\n";

$c = version_update($a_version_number, 1);
echo 'Next Version: ' . $c . "\n";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download