Jump to content


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


PHP code stored in database

Recommended Posts

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?


Share this post

Link to post
Share on other sites
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'.
    $content = preg_replace_callback($pattern, 'execphp_fix_tag', $content);
    eval(" ?> $content <?php ");
    $output = ob_get_contents();
    return $output;
echo execphp_eval_php($content['page_content']);[/code]

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.