re: Home Site = http://mobiledetect.net/
re:这个脚本= Mobile_Detect.php
在这里下载脚本:https://github.com/serbanghita/Mobile-Detect
该脚本能够很好地检测用户设备的不同参数。
然而,我目前是这样检测这些参数的:
// each part of the IF statement is hard-coded = not the way to do this
if($detect->isiOS()){
$usingOS = 'iOS';
}
if($detect->isAndroidOS()){
$usingOS = 'Android';
}
echo 'Your OS is: '.$usingOS;
我的目标是使用FOREACH通过这个脚本中的各种数组迭代来确定用户的设备参数。我需要“($检测->isXXXXOS())”是动态的.(这将基于密钥)。结果将显示密钥。但检测是基于价值的。
另外,由于我的网页使用了一个请求来访问这个脚本.在Mobile_Script.php脚本中,数组受到“保护”。我认为这也给我带来了问题(但我不确定)。
任何帮助都是非常感谢的。
发布于 2013-07-29 05:31:35
你可以试着用这样的东西:
$OSList = $detect->getOperatingSystems();// will give array of operating system name => match params
foreach($OSList as $os_name=>$os_params/*unused*/)
{
$method = 'is'.$os_name;
if($detect->$method())
{
$usingOS = $os_name;
}
}
发布于 2013-07-29 05:30:17
在foreach
循环中,可以调用dynamic method
,如下所示:
$array = array('Android','Windows','Linux','Mac');
foreach( $array as $value) {
$method = "is{$value}OS";
if($detect->$method()) {
$os = $value;
echo "Your OS is : {$os}";
}
}
请重新排列您想要的代码。我举个例子。
https://stackoverflow.com/questions/17925295
复制相似问题