dynamic title tag generation?

From: Date: Sat, 14 Sep 2002 01:52:26 +0000
Subject: dynamic title tag generation?
Groups: php.general 
Request: Send a blank email to php-general+get-116342@lists.php.net to get a copy of this message
Allo.. I have a small CMS that I'm in the process of creating and was wondering how I would achieve <title> tags that match the directory name & file name the visitor is viewing dynamically.. I'm a newbie, so please bear with me.. I have a head.php file which has the following line: echo "<title> DOMAIN - ? - ? </title>\n"; The head.php is included in each and every file displayed thru-out my site and has all the obvious opening html, head & opening body tags.. In place of the ?'s in the title tag above, I would like to dynamically change this.. For example, say I have a file located at the following URL: http://domain.com/php/tut.one.php I want to be able to have the title tag for that specific page read: DOMAIN - PHP - Tutorial 1 Yet if I have a file located here: http://domain.com/cgi/tut.four.php I would want this to be output for this specific page's title tag: DOMAIN - CGI - Tutorial 4 It's kind of similar to hotscripts.com and how their directory set up and their title tag corresponds to the directory names, but I don't want a directory structure as my title tag.. As my head is the first included file following the opening <?php tag, I wasn't sure how to go about this.. If I created a variable such as $title = "DOMAIN - PHP - Tutorial 4"; for each page title, the head would be read (and I assume parsed) before the actual variable.. I could put the $title variable above the include("head.php"); line, but it creates more hassle editing each file to add a $title variable and seems like somewhat sloppy coding.. This is also why I don't name my files specifically how I want the title tag to display them and use $request_uri or some similar reserved variable.. Is there an easy way to create a function to read the directory and file names and have it changed to display how I have my desired title tag output examples above? If someone could point me to the correct function() names and how to combine them if it's not obvious in the manual, I'd really appreciate it.. I don't need the manual's URLs, I can search the manual and don't want someone else doing my work for me.. I'll attempt to build the function myself, but a small example would be nice as I'm still learning and not sure how to combine all functions using the correct and most efficient syntax.. Similarly, if you've happen to come across any tutorials aside from php.net that cover this, please share the URL(s).. I've searched google, hotscripts and resourceindex among other places, but can't seem to find what I'm looking for.. TIA.. Hope I made sense.. Take care.. peace.. eriol

« previous php.general (#116342) next »