Jump to content


Photo

Echo a PHP Script


  • Please log in to reply
3 replies to this topic

#1 MB Works

MB Works
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 10 March 2006 - 02:38 AM

Hey.

Im having a problem, and i cant find the solution because i really dont know the command for do it.
I have a DB with scripts. For example

Table: Test, Column: Script, Row: <?php something ?>

I want to run that PHP code. But if i do and echo display "<?php something ?>";

$query = "SELECT * FROM codes";
$result = mysql_fetch_array($query, MYSQL_ASSOC);

echo $result['script'];

Where script = "<?php something ?>"
And echo return "<?php something ?>" as HTML
I want to Run <?php something ?>

How i can run that PHP code before the HTML?

Thanks

#2 k.soule

k.soule
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationIllinois

Posted 10 March 2006 - 02:54 AM

Use eval(), it will look something like --

eval($result['script'];);

maybe eval($result['script'] . ';');

I'm not sure of the syntax, I have never used it.

#3 MB Works

MB Works
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 10 March 2006 - 03:07 AM

It worked, but now my problem is:
$var = "<table><tr><td><?php echo "dynamicvalue" ?></td></tr></table>";
echo eval($var);

Return:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
Parse error: parse error, unexpected '<' in functions.php : eval()'d code on line 1
[/quote]

eval only work if: eval("echo dynamicvalue;")

Theres a way to run a Mixed Variable? or i need to filtrer all the code (god)

And Thanks for the reply

#4 MB Works

MB Works
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 10 March 2006 - 03:20 AM

I got it

ob_start();
eval ('?>' . $text);
$text = ob_get_clean();

Thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users