Forum Moderators: coopster
any body knows how to display a variable before it is defined?
You can't display a variable that is not yet defined! PHP files are parsed top to bottom, so it needs to be defined above where you want to use it. So, may be you can just change the order...
<?php $title = "Music Wallpapers"; ?>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<?php print $title; ?>
</body>
on the
include file is where i have the title tags . do u think it will work?
well it doesnt work for me any idea of how to do it
[edited by: eelixduppy at 5:15 pm (utc) on Feb. 19, 2009]
[edit reason] exemplified [/edit]
is like if it was thins way
<head><?php $title = "Music Wallpapers"; ?>
<title><?php print $title; ?> </title>
</head>
<body>
<?php print $title; ?>
</body>
but it doesnt work
[edited by: eelixduppy at 5:16 pm (utc) on Feb. 19, 2009]
[edit reason] exemplified [/edit]
Likewise, it should also work by including an external file. But I would guess there is something wrong with your head_tag.php file if it is not?
By including it the way you are, it would need to be something like:
<?php
echo '<title>'.$title.'</title>';
?>
Including the file via the filesystem and not through an http call will allow your $title variable to work. It's on you to figure out the location of the file on your system.
i think i cannot do it the way you say
<?php include $_SERVER['DOCUMENT_ROOT'].'/source/modules/php/head_tag.php'; ?>
Are you familiar with the values available in the _SERVER variable?
Dump phpinfo() to see - [php.net...]
Very useful...