Click to See Complete Forum and Search --> : Parse PHP within a variable


Daniel T
02-12-2005, 05:35 PM
Hey all.

I am in the process of writing a CMS, and I would like to store the HTML for it all in one file, instead of a header and footer file. To do that, I have this file, called struct.php:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title><?php echo $page -> title; ?></title>
<link rel="stylesheet" href="<?php echo $page -> style; ?>" />
</head>
<body>
<!--content-->
</body>
</html>And then the index.php file in the parent directory is as follows:<?php
require_once("class_lib/core.php");
$page = new pageInfo;

list($page_head, $page_foot) = explode("<!--content-->", file_get_contents("html/struct.php"), 2);
echo $page_head;
// this is where all content is outputted
echo $page_foot;
?>
Now, this works all fine and good. But of course, when it outputs the code in the $page_head and $page_foot variables, it doesn't parse the PHP that was within them from the struct.php file. Is it possible to get it to parse the code within the variables?

Thanks in advance,
Dan

pyro
02-12-2005, 08:41 PM
eval (http://www.php.net/manual/en/function.eval.php), I suppose, though there may be a better way of doing it than that...

Daniel T
02-12-2005, 08:51 PM
Originally posted by pyro
eval (http://www.php.net/manual/en/function.eval.php), I suppose, though there may be a better way of doing it than that... Hmmm, thanks, but it seems that it wants to parse the entire file "division" as PHP instead of just what is in the PHP tags :(

pyro
02-12-2005, 08:53 PM
See if this helps you: http://www.ryanbrill.com/archives/including-content-with-php/

Daniel T
02-12-2005, 09:02 PM
Originally posted by pyro
See if this helps you: http://www.ryanbrill.com/archives/including-content-with-php/ It very much does, thanks a million!

pyro
02-12-2005, 09:13 PM
Sure thing :)

BeachSide
02-12-2005, 09:35 PM
Originally posted by pyro
See if this helps you: http://www.ryanbrill.com/archives/including-content-with-php/

Oh nice man! Something new for me to wrap my head around thanks!:D