Check minimum version of PHP


/ Published in: PHP
Save to your folder(s)

Easy check (:

**UPD**
You can just use [version_compare()](http://ca.php.net/manual/en/function.version-compare.php) function.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.