Forum Moderators: coopster

Message Too Old, No Replies

Get PHP to execute

         

stidj

11:14 pm on Aug 8, 2008 (gmt 0)

10+ Year Member



I know everyone says use eval but I've tried different variations and I don't think it will solve my problem.

The basic structure of my code is like this:

<?
$content = generate_user_content();
echo $content;

?>

$content would be created by a function that retrieves the content from a database, basically just HTML.

My question is that if I want to retrieve and execute PHP code from the database instead of interpreting it as HTML how would I do it?

Thanks for everyone's help as usual.

mrscruff

12:42 pm on Aug 11, 2008 (gmt 0)

10+ Year Member



make sure that that database entry starts with <?php and ends with ?>

the use the following:

eval($content);

see:
[uk2.php.net...]

stidj

5:26 am on Aug 16, 2008 (gmt 0)

10+ Year Member



Thanks mrscruff but I've tried all of this stuff and it doesn't work for me for some reason.

I created a database entry with the following:
<?

echo "Hello";

?>

Tried eval($content);

But the result in the output of the HTML is simply just:

echo "Hello";

stidj

8:28 am on Aug 16, 2008 (gmt 0)

10+ Year Member



I solved it, it was the strange way I put together my code and template.

I still have another problem with eval. Is it possible to force the eval'd code to be stored in a variable rather than executing and showing the output right away?

I'm having trouble wrapping it around my template.

stidj

9:00 am on Aug 16, 2008 (gmt 0)

10+ Year Member



what a night lol
Now I'm getting errors because I have used \" to escape double quotes and PHP is complaining on the eval:

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in

stidj

9:03 am on Aug 16, 2008 (gmt 0)

10+ Year Member



The tricky part is that of course if I use stripslashes, then the double quotes become unencapsulated and I will get errors still.

Is there an easy solution to this?