PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Jay
Forum Newbie
Posts: 22 Joined: Fri Jul 12, 2002 8:36 am
Location: KUL, Malaysia
Post
by Jay » Sun Aug 18, 2002 3:18 am
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?
aaronhall
DevNet Resident
Posts: 1040 Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:
Post
by aaronhall » Sun Aug 18, 2002 4:47 am
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
Jay
Forum Newbie
Posts: 22 Joined: Fri Jul 12, 2002 8:36 am
Location: KUL, Malaysia
Post
by Jay » Sun Aug 18, 2002 5:45 am
excellent, i had forgotten all about eval() ... thanks!