drqj8605
2017-06-08 19:02
浏览 119
已采纳

如何在PHP中动态获取页面标题

I am getting my main pages title but when it comes to getting inner pages (variable post) it's not working.

$path=$_SERVER['PHP_SELF'];
$page_title=basename($path);
switch($page_title){
    case 'index.php':
        $title="Welcome to the the website";
        $description="description goes here";
        break;
    case 'about.php':
        $title="Welcome to the the website";
        $description="somehtinfd";
        break;
    case 'career.php':
        $title="Welcome to the the website";
        $description="ome textr";
        break;   
    /*IT's NOT WORKING HERE*/
    case 'post.php?post_id=1':$title="graphics design services";
        $description= "about ";
        break;
}

图片转代码服务由CSDN问答提供 功能建议

我正在获取我的主页标题,但是当涉及获取内页(变量帖)时,它无法正常工作。< / p>

  $ path = $ _ SERVER ['PHP_SELF']; 
 $ page_title = basename($ path); 
switch($ page_title){
 case'index.php'  :
 $ title =“欢迎来到网站”; 
 $ description =“描述在这里”; 
 break; 
 case'aber.php':
 $ title =“欢迎来到网站”  ; 
 $ description =“somehtinfd”; 
 break; 
 case'employe.php':
 $ title =“欢迎来到网站”; 
 $ description =“ome textr”; 
 break;  
 / * IT不在这里工作* / 
 case'post.php?post_id = 1':$ title =“graphics design services”; 
 $ description =“about”; 
 break; 
} 
    
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doumouyi4039 2017-06-08 19:36
    已采纳

    I think you can use get().

    case 'post.php':
        If($_GET["post_id"]== "1"){ 
            $title="graphics design services";
            $description= "about ";
        }elseif($_GET["post_id"]== "2"){
    
        }
        break;
    

    So use case to get the page post, the use get to get the ID.

    已采纳该答案
    打赏 评论
  • dongwan5381 2017-06-08 19:16
    <title> <?php echo $title; ?> </title>
    <meta type="description" content="<?php echo $description ?."</meta>
    
    打赏 评论

相关推荐 更多相似问题