Setting a requirement of PHP 5.4 or higher

103 views Asked by At

I need to require at least PHP 5.4 in my app.

The current code detects only 5.0 or higher:

$phpv=phpversion();
$t=explode(".", $phpv);
if($t[0]>=5)
    $ok=1;
else
    $ok=0;

Typing 5.4 or 54 instead of 5 does not work properly.

2

There are 2 answers

0
Guillaume Fache On BEST ANSWER

What about using the second part of the explode :

if($t[0]>=5 && $t[1]>=4)
...

Hope this helps.

0
IonuČ› G. Stan On

Use version_compare:

if (version_compare(PHP_VERSION, '5.4.0') < 0) {
    echo 'Minimum required version is 5.4.0. You have: ' . PHP_VERSION . "\n";
}