dou47732 2012-10-13 12:26
浏览 39

使用PHP将实时ID添加到BODY

I'm using the php code:

<body id="<?php echo str_replace("index.php?","",(basename($_SERVER['REQUEST_URI'],".php"))); ?>">

and

<?php
    if(isset($_GET['start'])){
     include('includes/start.php');
    }else if(isset($_GET['help'])){
     include('includes/help.php');
    }else{
     include('includes/start.php');
    }
?>

It works great - cutting index.php?help to "help" and index.php?start to "start" in body ID. But when I enter index.php in body ID is "index" not "start". Is there any way to tell index.php with included start.php to display "start" id body ID?

UPDATE

It should work dynamically - body ID is name of included .php file, something like this code:

<?php 
   $page = str_replace(array( 'server_name', 'index', '?',  '/', '.php'), '', $_SERVER['REQUEST_URI']);
   $page = $page ? $page : 'start';
?>

<body id="<?php echo $page ?>">
  • 写回答

2条回答 默认 最新

  • duandao1931 2012-10-13 12:36
    关注

    Am not sure i get you 100% but you can try

    $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);
    

    If you run index.php?help it would include include ('includes/help.php'); and also output

    <body id="help"  >
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大