Jump to content

Executing a string perhaps?


benmay.org

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...
Link to comment
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.)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.