Posted By

kirik on 08/30/09


Tagged

php check version minimum


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Nanobyte
umang_nine


Check minimum version of PHP


 / Published in: PHP
 

Easy check (:

UPD You can just use version_compare() function.

  1. function phpMinV($v)
  2. {
  3. $phpV = PHP_VERSION;
  4.  
  5. if ($phpV[0] >= $v[0]) {
  6. if (empty($v[2]) || $v[2] == '*') {
  7. return true;
  8. } elseif ($phpV[2] >= $v[2]) {
  9. if (empty($v[4]) || $v[4] == '*' || $phpV[4] >= $v[4]) {
  10. return true;
  11. }
  12. }
  13. }
  14.  
  15. return false;
  16. }
  17.  
  18.  
  19. /* ---- Newer than 4 ---- */
  20. if (phpMinV('4')) {
  21. // .....
  22. }
  23. // or
  24. if (phpMinV('4.*')) {
  25. // .....
  26. }
  27.  
  28. /* ---- Newer than 5.1 ---- */
  29. if (phpMinV('5.1')) {
  30. // .....
  31. }
  32. // or
  33. if (phpMinV('5.1.*')) {
  34. // .....
  35. }
  36.  
  37. /* ---- Newer than 5.2.3 ---- */
  38. if (phpMinV('5.2.3')) {
  39. // .....
  40. }

Report this snippet  

You need to login to post a comment.