The*_*rix 1 html php variables if-statement
这很简单,但我想我在这里缺少一些关键的东西:
<?php
$title = " | Unlimited Motors";
if (basename(__FILE__) == "index.php") {
global $title;
$title = "Home"." | Unlimited Motors";
}
if (basename(__FILE__) == "contact.php") {
global $title;
$title = "Contact Us"." | Unlimited Motors";
}
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $title; ?></title>
Run Code Online (Sandbox Code Playgroud)
你会认为这么简单的事情会起作用.
唉,事实并非如此.该echo $title;内的部分<title></title>不拿起改变的变量.它简单地显示"|无限电机",因为它没有if ()改变它.
我对这些全局变量和东西有点困惑,所以有人可以在这里解释错误吗?
更新:似乎我忘了添加一些我认为不重要的东西:
1)是的,我已经basename(__FILE__)在主体测试并得到了"index.php".
2)是的,我在头文件中使用它,然后included在其他文件中.