Breaking News
Home / Web / PHP / PHP Snippets / How to get the current PHP version in the script and compare?

How to get the current PHP version in the script and compare?

Snippet

The PHP version is stored in the PHP_VERSION variable and is available to the script at runtime. This with the version_compare function we can evaluate and compare and do the required action as shown below

  1. // _Checks PHP Version
  2. function checksPHPVersion() {
  3.  
  4.       //check if this is less than 5.2.5
  5.     $check_525 = (version_compare(PHP_VERSION,‘5.2.5’) >= 0)?1 : 0;
  6.  
  7.     //check if this is greater than 5.3.0
  8.     $check_php_530 = (version_compare(PHP_VERSION,‘5.3.0’) >= 0)?1 : 0;
  9.  
  10.     // perform the desired operation
  11. }

<!>

[pb_builder]

Check Also

How to list files in a directory in PHP?

<?php if ($handle = opendir(‘/path/to/directory’)) {     echo "Directory handle: $handlen";     echo …

Leave a Reply