我一直在爲我的網站製作一個header.php文件,並且希望頁面的標題標籤根據您訪問的頁面進行更改。正確地在PHP函數中源代碼頁面
它似乎只適用於首頁!
這是我寫的函數:
<?php
$directoryURI = $_SERVER['REQUEST_URI'];
$path = parse_url($directoryURI, PHP_URL_PATH);
$components = explode('/', $path);
$first_part = $components[1];
$title = "";
$jumbotitle = "";
$url = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if(strpos($url, '/') !== false){
$title = "Home";
$jumbotitle = "Home";
}if(strpos($url, 'about') !== false){
$title = "About";
$jumbotitle = "About";
}
if(strpos($url, 'contact') !== false){
$title = "Contact";
$jumbotitle = "Contact";
}
?>
有什麼建議?
去你家和回聲'$ url' ...最新輸出? – Twinfriends