News:

Please note these forums are mostly a testing ground for my SMF work and I don't really use them otherwise.

Main Menu

Paste-1256012275:v:use_geshi-1:v:type-php

Started by Guest, Oct 20, 2009, 04:17 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Guest

function matchPackageVersion($cur_ver, $for)
{print_r($cur_ver); echo '//'; print_r($for); echo "\n";
   // Setup an array of versions.
    $versions = explode(',', $for);

   foreach ($versions as $ver)
   {
      // A wildcard (*) version.
      if (strpos('*', $ver))
      {
         // Add a range to the end of $versions.
         array_push($versions, str_replace('*', '', $ver) . '-' . str_replace('*', 'z', $ver));
      }
      // Check if there is a range.
      if (strpos('-', $ver))
      {
         // You can only have one dash for a range. Otherwise it would be rangeS.
         if (substr_count($ver, '-') == 1)
         {
            list($lower, $upper) = explode('-', $ver);
            if (version_compare($lower, $cur_ver, '>=') && version_compare($upper, $cur_ver, '<='))
               return true;
         }
         // Uh oh, there are two or more dashes in this!
         else
         {
            $ranges = explode('-', $ver);
            foreach ($range as $range)
            {
               if (!isset($start))
                  $start = $range;
               else
               {
                  array_push($versions, $start . '-' . $range);
               }
               $start = $range;
            }
         }
      }
      else
         // Return true if we found the current version in the list of versions.
         if (version_compare($ver, $cur_ver, '=='))
            return true;
      
   }
   return false;
}