Jump to content


Executing PHP code from database (eval?)


  • Please log in to reply
4 replies to this topic

#1 Guest_thegooner_*

Guest_thegooner_*
  • Guests

Posted 03 July 2006 - 02:37 PM

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

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 03 July 2006 - 02:59 PM

<?php

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

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

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 Gooner

Gooner
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 03 July 2006 - 03:13 PM

No, that doesn't work.

#4 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 03 July 2006 - 06:51 PM

Perhaps you should be more specific. What 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...
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#5 TheIdeaman

TheIdeaman
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 19 August 2006 - 03:18 PM

Droping the  '<?php' part worked for me.

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

That should do it.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users