我正在使用php代码:
<body id="<?php echo str_replace("index.php?","",(basename($_SERVER['REQUEST_URI'],".php"))); ?>">
和
<?php
if(isset($_GET['start'])){
include('includes/start.php');
}else if(isset($_GET['help'])){
include('includes/help.php');
}else{
include('includes/start.php');
}
?>
它工作得很好 - 切割索引.php帮助"帮助"和索引.php?开始在身体 ID 中"开始"。但是当我输入索引时.php正文 ID 中的是"索引"而不是"开始"。有没有办法告诉索引.php包含 start.php 以显示"开始"ID 正文 ID?
更新
它应该动态工作 - body ID 是包含.php文件的名称,类似于以下代码:
<?php
$page = str_replace(array( 'server_name', 'index', '?', '/', '.php'), '', $_SERVER['REQUEST_URI']);
$page = $page ? $page : 'start';
?>
<body id="<?php echo $page ?>">
不确定我能得到你 100%,但你可以试试
$id = $_SERVER['QUERY_STRING'];
$bodyID = $id;
switch ($id) {
case "help" :
include ('includes/help.php');
break;
default :
$bodyID = "start";
include ('includes/start.php');
break;
}
printf("<body id="%s" >", $bodyID);
如果您运行index.php?help
它将包括include ('includes/help.php');
和输出
<body id="help" >
最好改用这个:
<?php
$ids = 'start,help,something';
$ids = explode(',',$ids);
$included = 0;
foreach ($ids as $id) {
if (isset($_GET[$id])) {
include('includes/'.$id.'.php');
$included = 1;
break;
}
}
if (!$included) include('includes/'.$ids[0].'.php');
?>
然后:
<body id="<?php echo $id; ?>">