Jump to content

Archived

This topic is now archived and is closed to further replies.

Guest thegooner

Executing PHP code from database (eval?)

Recommended Posts

Guest thegooner
Hi

I have a field in a database that contains a mixture of html and php

example:

<table><tr><td>hello world</td>
<td><?php echo "hello again"; ?></td>
</table>

I want to call this and execute it within a php page.

I get the above text from the database and load it into a variable called $dtext.

How do I execute the php within the html I just got form the database.

I've tried using "eval" but only get a blank page.

Anyone help on this one?

Thanks

Share this post


Link to post
Share on other sites
[code]<?php

$mixture = <<<MIX
<html>
<body>
Today is <?php \$date = getdate(); echo \$date['weekday']; ?>.
</body>
</html>
MIX;

echo eval('?>' . $mixture . '<?php');

?>[/code]

Share this post


Link to post
Share on other sites
Perhaps you should be more specific. [i]What[/i] doesn't work? Are you getting an error from the code I posted? Did you try implementing it into what you have? Help is mutual...

Share this post


Link to post
Share on other sites
Droping the  '<?php' part worked for me.

Change:
[code]echo eval('?>' . $mixture . '<?php');[/code]
To:
[code]echo eval('?>' . $mixture);[/code]

That should do it.

Share this post


Link to post
Share on other sites

×

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.