gpt4 book ai didi

php - 解析错误: syntax error, unexpected '$os' (T_VARIABLE) PHP Error

转载 作者:行者123 更新时间:2023-12-03 08:29:57 28 4
gpt4 key购买 nike

我正在使用以下代码来尝试并打印用户的操作系统:

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")
{

}
?>

我得到错误

Parse error: syntax error, unexpected '$os' (T_VARIABLE) in C:\xampp\xamppfile\htdocs\ProjectSite\includes\identifier.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";
}

?>

关于php - 解析错误: syntax error, unexpected '$os' (T_VARIABLE) PHP Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22324219/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com