解析错误:语法错误,意外的'$ os'(T
我正在使用以下代码来尝试打印用户的操作系统:
标题:
<?php
$user_agent = getenv("HTTP_USER_AGENT");
if (strpos($user_agent, "Win") !== FALSE)
$os = "Windows";
else (strpos($user_agent, "Mac") !== FALSE)
$os = "Mac";
?>
身体:
<?php
if($os = "Windows")
{
}
elseif($os == "Mac")
{
}
?>
我收到错误
解析错误:语法错误,意外的'$ os'(T_VARIABLE)位于C: xampp xamppfile htdocs ProjectSite includes identifier.php第7行
<?php
$user_agent = getenv("HTTP_USER_AGENT");
if (strpos($user_agent, "Win") !== FALSE) {
$os = "Windows";
}
else if(strpos($user_agent, "Mac") !== FALSE) {
$os = "Mac";
}
?>
你不能在else语句中使用else if
条件,并且在使用它之前还有实践声明你的变量,
$os = "";
if (strpos($user_agent, "Win") !== FALSE)
$os = "Windows";
else if(strpos($user_agent, "Mac") !== FALSE)
$os = "Mac";
链接地址: http://www.djcxy.com/p/69601.html