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

How get page title dynamically in PHP

我正在获取我的主页标题,但是在获取内页(变量 post)时它不起作用。

$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;
}
<title> <?php echo $title; ?> </title>
<meta type="description" content="<?php echo $description ?."</meta>

我想你可以使用 get()。

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

    }
    break;

所以用case获取页面post,用get获取ID