Jump to content


Photo

PHP code stored in database


  • Please log in to reply
1 reply to this topic

#1 martyf

martyf
  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 13 April 2006 - 07:14 AM

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

#2 martyf

martyf
  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 13 April 2006 - 07:35 AM

I've actually just solved this one myself with the assistance of a WordPress plug in (http://www.soeren-we...18/exec-php.zip)
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']);





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users