2015-11-02 146 views
0

如何使用php检测iOS版本。我试图用解决方案$_SERVER['HTTP_USER_AGENT']工作,但它显示:如何使用php检测iOS版本?

Mozilla/5.0 (iPhone; U; CPU iPhone OS 8_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7 

我想只显示OS 8_0

任何帮助,将不胜感激。

+3

去http://stackoverflow.com/questions/25325499/detect-ios-version-lower-than-ios-8-php –

回答

0

至于你提到你有使用$_SERVER['HTTP_USER_AGENT']

所以输出

的Mozilla/5.0(iPhone; U; CPU iPhone OS 8_0喜欢Mac OS X; EN-US)为AppleWebKit/532.9 (KHTML,例如Gecko)版本/ 4.0.5移动/ 8A293野生/ 6531.22.7

在上述输出被包含的该版本(见粗体文本以上)

if (strpos($_SERVER['HTTP_USER_AGENT'], 'OS 8_0') !== false) 
{ 
    echo "This is iOS 8"; 
} 
else{ 
    echo "This is not iOS 8";} 
} 

读 - Detecting iOS Version Number from User Agent using Regular Expressions