Page 1 of 1

Parsing PHP code that's stored in a database.

Posted: Sun Aug 18, 2002 3:18 am
by Jay
I am stuck with trying to parse PHP codes that are stored together with text in a database. For example, 1 column in my db stores text like this:

Code: Select all

This is just text. <?php echo " This WAS PHP. "; ?>This is text again.
Anybody know how I can get the PHP above to work when i retrieve the data? Is this even possible? :)

Posted: Sun Aug 18, 2002 4:47 am
by aaronhall
Very possible.

Use some regexps to parse out the PHP code into a string on its own without the <? and ?>. Then use the eval() function on that string.

More info here: http://www.php.net/manual/en/function.eval.php

Good luck,
Aaron

Posted: Sun Aug 18, 2002 5:45 am
by Jay
excellent, i had forgotten all about eval()... thanks!