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.
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";
}
What about using the second part of the explode :
Hope this helps.