Forum Moderators: coopster
Say I have four php files, one called header, one called home, one called content and the 4th called footer.
Now, in the home.php I include the other 3 to make my web page. Now is there any way that using the name of the home.php it can create the title, so <title>Home</title>?
So whatever is the name of the php file with all the includes, it takes that filename and used that for its title tag.
Or is there another way that I can do all this?
I'd like to try and only use a header and footer once if possible. Sorry for the bad explanation.
Thanks
[edited by: hOtTiGeR123 at 6:01 pm (utc) on June 9, 2008]
//header.php
<?
function getScriptName($url){
$name = "Undefined Page"; //default name
$pattern = "/\/[a-zA-Z0-9\_\-]+\.php/"; //finds file name based on extension
preg_match($pattern ,$url, $matches);if(is_array($matches) && !empty($matches[0])){
$name = $matches[0]; //gets script name
}
$name = str_replace("/", "", $name); //replaces first slash
$name = preg_replace("/\.(php¦¦html)/", "", $name);//replaces the file extension
return $name; //returns name of script
}
?>
<html>
<head>
<title><? echo getScriptName($_SERVER['PHP_SELF']); ?> </title>
</head>