Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP检测Mac OS版本_Php_Macos_Operating System_User Agent - Fatal编程技术网

使用PHP检测Mac OS版本

使用PHP检测Mac OS版本,php,macos,operating-system,user-agent,Php,Macos,Operating System,User Agent,我已经创建了一个脚本,可以在互联网的帮助下检测windows的操作系统版本,但现在我只能检测Mac操作系统版本。我没有Mac操作系统来测试代码,并找出要使用什么,搜索谷歌并没有真正帮助我。 以下是我在Wiki上找到的版本: 例如,对于Windows,我发现: windows nt 6.1=windows 7 if (preg_match('/windows nt 6.1/i', $user_agent)) { $platform .= ' 7'; }

我已经创建了一个脚本,可以在互联网的帮助下检测windows的操作系统版本,但现在我只能检测Mac操作系统版本。我没有Mac操作系统来测试代码,并找出要使用什么,搜索谷歌并没有真正帮助我。 以下是我在Wiki上找到的版本:

例如,对于Windows,我发现: windows nt 6.1=windows 7

if (preg_match('/windows nt 6.1/i', $user_agent)) {

            $platform .= ' 7';

        }
如何检测Mac的数字版本? 这是我仅有的一块,但并非所有版本都准确:

if (preg_match('/macintosh|mac os x/i', $user_agent)) {

    $platform = 'Mac';

} 
    if (preg_match('/mac_powerpc/i', $user_agent)) {

        $platform .= ' OS 9';

    } elseif (preg_match('/macintosh/i', $user_agent)) {

        $platform .= ' OS X';

    }

如果您想要精确的结果,但今天仍然回家,请切换到UAparser库:

从他们的手册中:

require_once 'vendor/autoload.php';
use UAParser\Parser;

$ua = "Mozilla/5.0 (Macintosh; Intel Ma...";

$parser = Parser::create();
$result = $parser->parse($ua);

print $result->ua->family;            // Safari
print $result->ua->major;             // 6
print $result->ua->minor;             // 0
print $result->ua->patch;             // 2
print $result->ua->toString();        // Safari 6.0.2
print $result->ua->toVersion();       // 6.0.2

print $result->os->family;            // Mac OS X
print $result->os->major;             // 10
print $result->os->minor;             // 7
print $result->os->patch;             // 5
print $result->os->patchMinor;        // [null]
print $result->os->toString();        // Mac OS X 10.7.5
print $result->os->toVersion();       // 10.7.5

print $result->device->family;        // Other

print $result->toString();            // Safari 6.0.2/Mac OS X 10.7.5
print $result->originalUserAgent;     // Mozilla/5.0 (Macintosh; Intel Ma...
如果您使用:


不是我的解决方案。在发布我的问题之前,我已经发现了这一点。它没有说明如何检测单个操作系统版本,如OS9或OS10等。
"require": { 
    "ua-parser/uap-php": "dev-master"
}