Parse error: syntax error, unexpected '$os' (T

I'm using the following code to try and print the operating system of the user:

Header:

<?php
$user_agent = getenv("HTTP_USER_AGENT");

if (strpos($user_agent, "Win") !== FALSE)
$os = "Windows"; 
else (strpos($user_agent, "Mac") !== FALSE)
$os = "Mac";
?>

Body:

<?php
if($os = "Windows")
{

}
elseif($os == "Mac")
{

} 
?>

I get the error

Parse error: syntax error, unexpected '$os' (T_VARIABLE) in C:xamppxamppfilehtdocsProjectSiteincludesidentifier.php on line 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/69602.html

上一篇: 解析错误:语法错误,意外的T

下一篇: 解析错误:语法错误,意外的'$ os'(T