Jump to content

PHP code stored in database


martyf

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?

Cheers,
Marty
Link to comment
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'.
        '(((([\'\"])([^\\\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
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.