【发布时间】:2014-02-03 02:16:23
【问题描述】:
我在另一个 SO 问题中遇到了这个非常简单的移动检测功能。但是,我无法让它工作。
我将函数放入 PHP 代码中,然后调用该函数。
但是,它返回以下错误。
Parse error: syntax error, unexpected T_IF in web...index.php on line 11 on line 11
谁能发现我在下面的代码中做错了什么?提前感谢您的任何想法!
index.php:
<?php
function checkMobile() {
if (preg_match("/Mobile|Android|BlackBerry|iPhone|Windows Phone/",$_SERVER['HTTP_USER_AGENT']))
{
header("Location:mobile/index.php");
}
}
checkMobile()
?>
【问题讨论】:
-
试试这个库:mobiledetect.net
-
就您的问题而言,您的问题中是否粘贴了第 11 行?
-
第 11 行是上述行之一。我认为第 11 行实际上是 checkMobile() 但它正在触发该功能。当我取出 checkMobile() 时,页面加载没有问题。只有在包含对函数的调用时,我才会收到 T_IF 错误
-
mobiledetect 看起来不错,但我只想让这个简单的脚本正常工作
-
也许在 checkMobile() 后加一个分号?