Viewing Paste 393

Formated Paste

  1. function matchPackageVersion($cur_ver, $for)
  2. {print_r($cur_ver); echo '//'; print_r($for); echo "\n";
  3. // Setup an array of versions.
  4. $versions = explode(',', $for);
  5.  
  6. foreach ($versions as $ver)
  7. {
  8. // A wildcard (*) version.
  9. if (strpos('*', $ver))
  10. {
  11. // Add a range to the end of $versions.
  12. array_push($versions, str_replace('*', '', $ver) . '-' . str_replace('*', 'z', $ver));
  13. }
  14. // Check if there is a range.
  15. if (strpos('-', $ver))
  16. {
  17. // You can only have one dash for a range. Otherwise it would be rangeS.
  18. if (substr_count($ver, '-') == 1)
  19. {
  20. list($lower, $upper) = explode('-', $ver);
  21. if (version_compare($lower, $cur_ver, '>=') && version_compare($upper, $cur_ver, '<='))
  22. return true;
  23. }
  24. // Uh oh, there are two or more dashes in this!
  25. else
  26. {
  27. $ranges = explode('-', $ver);
  28. foreach ($range as $range)
  29. {
  30. if (!isset($start))
  31. $start = $range;
  32. else
  33. {
  34. array_push($versions, $start . '-' . $range);
  35. }
  36. $start = $range;
  37. }
  38. }
  39. }
  40. else
  41. // Return true if we found the current version in the list of versions.
  42. if (version_compare($ver, $cur_ver, '=='))
  43. return true;
  44.  
  45. }
  46. return false;
  47. }
Name:
Email:
Code/text to paste:
  • Enable code highlighting
  • Code Language:
  • A duck, cat and a goose walk into a bar. How many animals walked into a bar?:
Highslide for Wordpress Plugin