NYCPHP Meetup

NYPHP.org

[nycphp-talk] title display based on page view

yury at heavenspa.com yury at heavenspa.com
Tue Feb 10 11:18:46 EST 2004


Adam,

(quote)I have 51 actual pages and want to write a PHP function that looks at
the file name and can generate the correct HTML title (quote)

exactly :) wow it took me atleast 30-40 words to describe that, and you did
it in 1 sentance.. hehe

Not using a db... i'll check out your code - thanks.

regards
yury


----- Original Message ----- 
From: "Adam Maccabee Trachtenberg" <adam at trachtenberg.com>
To: "NYPHP Talk" <talk at lists.nyphp.org>
Sent: Tuesday, February 10, 2004 11:01 AM
Subject: Re: [nycphp-talk] title display based on page view


> On Tue, 10 Feb 2004 yury at heavenspa.com wrote:
>
> > Chris hrmm I guess I'm still 1/2 asleep. I'd like to help some pages get
> > relevant titles based on which page is displayed. So the example is like
so:
> >
> > i have 51 pages - each page is a state name : state.php
> >
> > i'd like to have 51 titles that have a few of the major cities from that
> > state.
> >
> > I'd like the title to be displayed based on the state.php page.. I guess
i
> > could do a huge swtich/case, but was wondering if there is a
smart/simple
> > way..
>
> Are you saying you have 51 distinct physical pages (new_york.php,
> connecticut.php, etc.) and want to write a PHP function that looks at
> the file name and can generate the correct HTML title? Or that you
> have 1 physical page (state.php) and 51 "virtual" pages?
>
> If you have the first, try placing something like this in a file
> that's included in all pages:
>
> $titles = array('new_york.php' => 'New York Title',
>                 'connecticut.php' => 'Connecticut Title',
>                 ...);
>
> $path_parts = pathinfo($_SERVER['PHP_SELF']);
> $title = $titles[$path_parts['basename']];
>
> ...
>
> print "<title>$title</title>";
>
> However, what you should really do is switch to the second setup and
> pull all content, including the title, out of a database based on a
> passed in page name. That solve the title problem and generalizes the
solution.
>
> -adam
>
> -- 
> adam at trachtenberg.com
> author of o'reilly's php cookbook
> avoid the holiday rush, buy your copy today!
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
>




More information about the talk mailing list