PHP's forward compatible version compare

Blog
PHP
Programming

Sometimes the code is forward compatible, for example when it's compatible with all future PHP5 releases, put PHP's version_compare function does not support this (Perhaps because they know that they always break compatibility with every minor release!!!). This function supports .x, for the above example it's : 5.x

It's also shared here

    function versionCompare($version1,$version2,$operand) {
        $v1Parts=explode('.',$version1);
        $version1.=str_repeat('.0',3-count($v1Parts));
        $v2Parts=explode('.',$version2);
        $version2.=str_repeat('.0',3-count($v2Parts));
        $version1=str_replace('.x','.1000',$version1);
        $version2=str_replace('.x','.1000',$version2);       
        return version_compare($version1,$version2,$operand);
    }
No votes yet