如何使用PHP基于页面名称创建动态HTML <title>标签?

How would I dynamically change my HTML title tag based on the .php/.html file name? Right now I am using a switch case to try and accomplish this, but I am not sure how to get the page name in order to compare it for each case. Here is my PHP code:

$prefix = 'MySiteTitle | ';

switch ($_GET['PHP_SELF']){
case 'www.mysite.php/home':
$pageTitle = 'Home';
}

And in my title tag, it goes:

<title><?php echo $prefix . $pageTitle ?></title>

This has not worked so far, as the $pageTitle variable is empty

You might mean $_SERVER['PHP_SELF'] and not $_GET['PHP_SELF'] (though you could've named your parameter that). Check that output

echo $_SERVER['PHP_SELF'] 

and make sure that echo matches 'www.mysite.php/home'

$prefix = 'MySiteTitle | ';

switch ($_GET['PHP_SELF']){
    case 'www.mysite.php/home':
        $pageTitle = 'Home';
     default:
         $pageTitle ='You are here';
}

You could do something like this :

$pageTitle = rtrim(basename(__FILE__), '.php');

But this is not a good idea, if you will most certainly not have a single content on each file.

You should do the assignment by yourself : $pageTitle = 'Article name';

Edit

With a header :

In the header file, you will have something like this : <title>My site | <?= $pageTitle ?></title>

And on the page visited by the user :

$pageTitle = 'My article';

require_once 'header.php';