The PHP code in DB sucks, but I was in situations where it should have been done, because my employer did not allow me to rewrite the system in such a way as to avoid it, so here is the general version of the solution we used:
$string = 'this <?php echo "is not"; ?> cool'; function exec_php($php_string) { return preg_replace_callback( '/<\?(?:php)?(.*)\?>/m', 'exec_php_embed', $string ); } function exec_php_embed(array $args) { if (count($args) != 2) { return ''; } list(,$code) = $args; ob_start(); eval($code); return ob_get_clean(); }
Note: VERY VERY CAUTION WITH THIS! DO NOT PERFORM THE USER'S CONTENT WITH THIS! Try replacing it as soon as possible!
Using eval() not just inefficient, it is dangerous when used even in a slightly improper way. Despite the fact that I really do not recommend using such things as it was above, I believe that this will be the solution to your immediate problem. I can not guarantee that he will not create more of his own problems;)
As GNU says:
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
source share