evaluating PHP source to a file.
| From: | indrek siitan | Date: | Sun, 18 Jun 2000 02:22:08 +0000 |
| Subject: | evaluating PHP source to a file. | ||
| Groups: | php.dev php.general | ||
| Request: | Send a blank email to php-dev+get-21660@lists.php.net to get a copy of this message | ||
Hi,
can anyone point me to a direction, how to solve the following
problem? I'm quite experienced in web programming, but it's my
first project with PHP.
I have a small content management system, from which I have to
generate a static snapshot.
I have:
* a template (which I can modify in any way if necessary)
* contents of the site in a table, which contains the following fields:
- filename (which the output file needs to be)
- page type (either "text" or "php", read below)
- source
now i need to go through the content table and generate static versions
of all the pages on the template. for the "text" type pages the content
needs to be the source in the table, for the "php" type pages it needs
to be the output of the php source in table.
in my humble mind (and with my previous EmbPerl experience) i thought
up a following solution:
* create the template as a PHP source, and let the content part be
something like:
--- 8< ---
global $pagedata;
if ($pagedata["pagetype"]=="php")
eval($pagedata["src"]);
else
echo $pagedata["src"];
--- 8< ---
* now in the "publish" page, create a loop that goes through all the
pages in the database:
--- 8< ---
$query="SELECT filename,pagetype,src FROM pages";
$res=mysql_query($query);
while($row=mysql_fetch_array($res)) {
$pagedata["pagetype"]=$row["pagetype"];
$pagedata["src"]=$row["src"];
$FD=fopen($row["filename"],"w");
--> $content=eval($template);
fwrite($FD,$content);
fclose($FD);
}
mysql_free_result($res);
--- 8< ---
The problem is how to catch the contents of the eval to a variable and
not print it out on a page. Can anyone share an idea? This thing needs
to be running by Sunday night, so I'm really out of time here.
And: I'm NOT SUBSCRIBED to these lists, so please answer in a private
mail.
Rgds,
Tfr
--==< tfr@cafe.ee >==< http://tfr.cafe.ee/ >==<
+1-504-4467425 >==--