function versionCompare($version1, $operator, $version2) {
$_fv = intval ( trim ( str_replace ( '.', '', $version1 ) ) );
$_sv = intval ( trim ( str_replace ( '.', '', $version2 ) ) );
if (strlen ( $_fv ) > strlen ( $_sv )) {
$_sv = str_pad ( $_sv, strlen ( $_fv ), 0 );
}
if (strlen ( $_fv ) < strlen ( $_sv )) {
$_fv = str_pad ( $_fv, strlen ( $_sv ), 0 );
}
return version_compare ( ( string ) $_fv, ( string ) $_sv, $operator );
}
var_dump ( versionCompare ( '2.9', '<', '2.9.6' ) ); // true
var_dump ( versionCompare ( '2.9', '>', '2.9.6' ) ); // false
var_dump ( versionCompare ( '2.9', '<', '3.0' ) ); // true
var_dump ( versionCompare ( '2.9', '<=', '2.8.9' ) ); // false
var_dump ( versionCompare ( '2.9', '!=', '2.8.9' ) ); // true
var_dump ( versionCompare ( '2.8', '!=', '2.8.0' ) ); // false
var_dump ( versionCompare ( '2.9', '==', '2.9.0' ) ); // true
var_dump ( versionCompare ( '2.9', '==', '2.9.1' ) ); // false
var_dump ( versionCompare ( '3.0 beta', '>', '2.9.9' ) ); // true