Browse Source

检测php版本号

萤火科技 3 years ago
parent
commit
e8dba667e3
1 changed files with 14 additions and 2 deletions
  1. 14 2
      public/install/index.php

+ 14 - 2
public/install/index.php

@@ -256,11 +256,12 @@ function getExtendArray()
     return $data;
 }
 
+// 检测php版本号
 function getPHPVersion()
 {
-    // 检测php版本号
     $version = phpversion();
-    if (version_compare($version, '7.4', '<') || version_compare($version, '7.4', '>')) {
+    $versionInt = versionToInteger(phpversion());
+    if ($versionInt < 70400 || $versionInt >= 70500) {
         echo "<span class=\"col-red\"><strong>{$version}</strong> (请使用php7.4)</span>";
         setIsNext(false);
     } else {
@@ -268,6 +269,17 @@ function getPHPVersion()
     }
 }
 
+/**
+ * 将版本转为数字
+ * @param string $version
+ * @return int
+ */
+function versionToInteger(string $version): int
+{
+    list($major, $minor, $sub) = explode('.', $version);
+    return intval($major * 10000 + $minor * 100 + $sub);
+}
+
 // 获取检测的路径数据
 function getIsWriteArray()
 {