benmay.org Posted July 16, 2006 Share Posted July 16, 2006 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 https://forums.phpfreaks.com/topic/14758-executing-a-string-perhaps/ Share on other sites More sharing options...
GingerRobot Posted July 16, 2006 Share Posted July 16, 2006 I could be wrong, but i think you need to use the eval() function:http://uk2.php.net/eval Link to comment https://forums.phpfreaks.com/topic/14758-executing-a-string-perhaps/#findComment-58897 Share on other sites More sharing options...
Joe Haley Posted July 16, 2006 Share Posted July 16, 2006 [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 https://forums.phpfreaks.com/topic/14758-executing-a-string-perhaps/#findComment-58901 Share on other sites More sharing options...
benmay.org Posted July 16, 2006 Author Share Posted July 16, 2006 That got it!! Thanks, and thanks for the promt (within 5 mins) Reply! Link to comment https://forums.phpfreaks.com/topic/14758-executing-a-string-perhaps/#findComment-58903 Share on other sites More sharing options...
Joe Haley Posted July 16, 2006 Share Posted July 16, 2006 Also, when using eval, it is [b]SO[/b] important to validate user input! This cannot be stressed enogh. Link to comment https://forums.phpfreaks.com/topic/14758-executing-a-string-perhaps/#findComment-58907 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.