Forum Moderators: coopster
If I use include to get a footer that declares variables which are used in the wrapper document, will the PHP parser loop through the HTML to ensure that all variables are used, or will they be ignored?
I'm betting ignored, but that's not what I want, so here's another question. Is there a way to get the information form the include to the top of the master document?
Many thanks.
Right now I have one file with header, footer, sidebars and a single include in the center.
I would like to contain the header information such as page title, and meta descriptions, keywords, etc., in the same file as the content, but if the file is parsed in a linear mode, my current design makes it too late to use the include in the center.
I know diddly about using databases, so that is out, but one thought that comes to mind is ...
Would it be possible to put the include file at the head of the file, possibly just after the <HTML> tag, and have everything in it treated as a variable? Then, put it in place using said variables instead of includes later in the document?
How would you treat an entire section of formatted HTML as a variable?
function myList()Then in your script:
{
global $name, $address, $phone;
$content =
"<ul>
<li>Name: $name</li>
<li>Address: $address</li>
<li>Phone: $phone</li>
</ul>";
return $content;
}
.Another way to parse variables is the eval() [php.net] function.
.
.
<?php
$name = 'Name';
$address = '123 Main Street';
$phone = '555-1212';
?>
<body>
<? php print myList(); ?>
</body>
.
.
.
About midnight last night I was able to work out another way.
I put the include construct before the <HTML> tag and made everything in the include file a $var.
I declared a var in my include file/page (as in $var1 = " ...) and typed in a gazoodle of HTML, then in that same HTML, I was using vars from my main page that I needed to build dynamic links which were to be made whole as the pages were rendered.
All I had to remeber was to use single quotes where HTML tags required quotes, such as in all <a href = '... tags through my HTML.
Then on my main page, I called the $var1 where I would ordinarily have used an include construct.
When I called the $var1 on my main page, I had to remember to use the format ${var1} (with the curly barces) to insert the complex $var1 and it's nested vars.
New bucaneer laugh? Var, var, varrr.
Anyhoo, that got it working for me, and I was just getting back to the forum this morning.
BTW - I tried the eval() and couldn't get it to return anything, which I believe I discovered it didn't, how do it work?
Thanks for your help.