Jump to content

Archived

This topic is now archived and is closed to further replies.

benmay.org

Executing a string perhaps?

Recommended Posts

Hey,
Here's the situation, I have a website with a template in /templates/boringtemplate/template.php
the template file is html with <?php echo($title) ?> along the way, normally, to display it dynamically, I just run all the queries, and include("templates/$templatedir/template.php") and it works great,

But, I am getting to the stage where my little cms cant be used by some clients due to them not having mysql etc.. I'm trying to figure out how I can generate a static page..

Here is what I've started on..

[code]
$filename ="static_$current_page.html";

$myFile= fopen($filename,'a');

if(! $myFile){ print ("File could not be opened."); exit;}
fputs($myFile, $string);
fclose($myFile);
[/code]

Thats fine, it will write $string to the desired html file. But.. How Can I get the string to include the answers the the php. In other words, I think I need to execute the php file, and save the result as a html file...

Share this post


Link to post
Share on other sites
I could be wrong, but i think you need to use the eval() function:
http://uk2.php.net/eval

Share this post


Link to post
Share on other sites
[code]$template = $whatever_source;
$template = str_replace('\\', '\\\\', $template);
$template = str_replace('"', '\\"', $template);
eval('$template = "' . $template . '";');[/code]

This will replace all variables within $whatever_source with their corresponding value in the calling script.

I suggest you use this method even for a mysql version, as it abstracts code from templates. (IMHO, an important thing to do.)

Share this post


Link to post
Share on other sites
Also, when using eval, it is [b]SO[/b] important to validate user input! This cannot be stressed enogh.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.