比较PHP中的通配符版本

I am building a Package Management System with Zend Framework 2. At one point i have to compare a package Version with a package dependency filter. The version has to be a complete version for example: "3.1.5". But the packate dependency filter can contain wildcards. For example "3.1", this means that the package dependency filter can be any versions from "3.1.0" to "3.1.AnyNumber".

What is the best way to find out if the package version "3.1.5" belongs the the package dependency filter of "3.1"?

i've already tried the PHP native version_compare function but that only seams to work for standardized complete versions.

Currently my solution is to explode both the version an the filter, and then compare the subVersions to the subFilters. But i'm not happy with my solution.

Thankx in advance

A little late, but I just stumbled upon the same problem.

My solution was to get the last digit in the dependency version filter and add 1, then use the third parameter of the version compare function to change to only "greater than" (not greater than or equal).

Also you need to check for lower version, using "less than or equal"

so in your case:

$pv = "3.1.5" // package version
$dv = "3.1" // dependency version filter    
$dv_max = substr($dv, 0, strrpos($dv, ".")+1).(1 + substr($dv, strrpos($dv, ".")+1));
// $dv_max = 3.2

return version_compare($dv_max, $pv, ">") && version_compare($dv, $pv, "<=")
// true or false

// transalates to: return "3.2" > "3.1.5" And "3.1" <= "3.1.5"
// works with range: "3.1" ... "3.1.Anything"