Reply to Re: Echo filename in <title>

Your name:

Reply:


Posted by Steve on 09/24/07 01:02

"geetarista" <geetarista@gmail.com> wrote in message
news:1190593035.326271.211030@22g2000hsm.googlegroups.com...
>I know this is probably very simple, but for some reason I can't get
> it to work. Basically, I want to use the filename of a web page
> within the <title> tags in the page <head>. So, if the filename is
> pictures.php, I want the title to be "Root title - Pictures", where
> the word "Pictures" is generated by PHP. So I just need PHP to look
> up the filename without the extension, capitalize the first letter,
> and then have the ability to call it within <title>.

<?
$pageTitle = 'Root Title - Pictures';
?>
<title><?= $pageTitle ?></title>

using the file name to derive text (other than literal 'pictures.php') is
voodoo magic at its finest...don't do it. the above is the simplest way to
implement what you want. you could also use a db to store the name and look
it up (use the script name, like $_SERVER['PHP_SELF'] as the key to the db
lookup).

if you do this the way you suggest, you've required that anyone who
developes pages on your site to somehow know they have to do something
special when naming scripts. file system, db, html, php are all different
layers of an application and each should be as self-contained, independent,
and isolated as possible. a good read for you would be 'ISO 7 layers' and
'code complete'.

if you still insist...

<?
$scriptName = !is_link(__FILE__) ? __FILE__ : readlink(__FILE__);
$pathInfo = pathinfo($scriptName);
$scriptName = ucwords(strtolower($pathInfo['filename']));
?>
<title><?= $scriptName ?></title>

as you can see, the first example is much more straight-forward.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация