douque9815
douque9815
2015-06-17 12:05
浏览 227
已采纳

设置PHP 5.4或更高版本的要求

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条回答 默认 最新

  • dongwen7730
    dongwen7730 2015-06-17 14:37
    已采纳

    What about using the second part of the explode :

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

    Hope this helps.

    点赞 评论
  • doulan6150
    doulan6150 2015-06-17 14:40

    Use version_compare:

    if (version_compare(PHP_VERSION, '5.4.0') < 0) {
        echo 'Minimum required version is 5.4.0. You have: ' . PHP_VERSION . "
    ";
    }
    
    点赞 评论

相关推荐