martyf Posted April 13, 2006 Share Posted April 13, 2006 I've got a concept in my head but I'm not sure if I'm going to be able to get it working. What I want to do is have a single page for the site, and store all of the content in a database - there by running the site off of one page pretty much. However, some of the 'content' code includes PHP code itself. So what I have set up as a prototype is content in a database which gets extracted and 'echoed' to the screen. This is fine for HTML-only content, but a problem occurs when PHP is within that HTML code.Is there a way that I can 'echo' the data to the screen, but to parse any PHP that may be contained before echoing. I have thought of a few ways around (writing a function to break up the string, or using the ob_start() features, but still have the issue of parsing the code.Does any one have any suggestions?Cheers,Marty Link to comment https://forums.phpfreaks.com/topic/7285-php-code-stored-in-database/ Share on other sites More sharing options...
martyf Posted April 13, 2006 Author Share Posted April 13, 2006 I've actually just solved this one myself with the assistance of a WordPress plug in (http://www.soeren-weber.net/data/2005/08/18/exec-php.zip)[code]function execphp_fix_tag($match){ $output = '<?php'. $match[2]. '?>'; return $output;}function execphp_eval_php($content) { $pattern = '/'. '(?:(?:<)|(\[))[\s]*\?php'. '(((([\'\"])([^\\\5]|\\.)*?\5)|(.*?))*)'. '\?(?(1)\]|>)'. '/is'; $content = preg_replace_callback($pattern, 'execphp_fix_tag', $content); ob_start(); eval(" ?> $content <?php "); $output = ob_get_contents(); ob_end_clean(); return $output;}echo execphp_eval_php($content['page_content']);[/code] Link to comment https://forums.phpfreaks.com/topic/7285-php-code-stored-in-database/#findComment-26499 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.