RE: [PHP] dynamic html <head> info

From: Date: Sun, 18 May 2003 14:57:20 +0000
Subject: RE: [PHP] dynamic html <head> info
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-148083@lists.php.net to get a copy of this message
> Somewhat general variable usage question I guess. Thanks to anyone that > has > a few minutes to enlighten me. > > Say 'head.php' contains the html <head>title, meta, etc...</head> block of > text, and 'content.php' has html content, and your index page looks like: > > <html> > <head> > <? require ("/usr/local/www/dubya.org/htdocs/common/head.php"); ?> > </head> > <body> > <? require ("/usr/local/www/dubya.org/htdocs/common/content.php"); ?> > </body> > </html> > > Can you populate variables in 'head.php' from vars in 'content.php,' even > though the head was included first? (and thus already processed?) > > eg. having <title><?php print $pagetitle; ?></title> in the head.php, and > <? > $pagetitle = "my page title"; ?> at the top of the 'content.php' file. No, you can't. It's like saying: echo $a; $a = 'foo'; and expecting to get 'foo' as output. You may want to use functions or classes that don't actually output your code, but return them to a variable. $content = get_content(); $pagetitle = $somevar_from_get_content; //global var or something $header = get_header(); //using $pagetitle somewhere echo "<html>$header<body>$content</body></html>"; ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/

« previous php.general (#148083) next »