Jump to content


executea php code in a variable


5 replies to this topic

#1 b3nji

    Young Padawan

  • Members
  • Pip
  • 14 posts

Posted 21 November 2005 - 06:54 PM

Can you execute a php code in a variable? from the database without it showing the code but acually DOING the code

#2 Programmerguy150

    Young Padawan

  • Members
  • Pip
  • 114 posts
  • Interests:Eating your soul<br />P2L<br />PHP<br />Tutorials<br />Eating your soul..

Posted 21 November 2005 - 09:27 PM

if you use things like:

<html>
<body>
blah
<?=$include?>
</body>
</html>

yes. And normally no. When you get a variable, it can be executed as PHP code, but isnt meant to, because it is echoed. But that above doesnt echo, just places it out.:) Or use the return function, I guess.

#3 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 21 November 2005 - 09:37 PM

Actually, i believe the eval() function is what he is looking for.

From what i know of your method, that simply echo's the code, and doesn't "run" it.

Edited by rc69, 21 November 2005 - 09:38 PM.


#4 HaloprO

    Requires Armed Escort

  • Members
  • PipPip
  • 310 posts
  • Gender:Male
  • Location:California, USA

Posted 22 November 2005 - 01:20 AM

Are you looking to do something like
<?php
$code = '<?php echo "hey!"; ?>':
echo $code;
?>
If so, do what rc69 said and use echo eval($code);

#5 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 22 November 2005 - 04:59 PM

Note, if you use the open/closing php tag's, then you'll want to close your php tag before "evaling" the code.
Example
<?
$code = '<? echo "blah"; ?>';
eval('?>'.$code);
?>


#6 HaloprO

    Requires Armed Escort

  • Members
  • PipPip
  • 310 posts
  • Gender:Male
  • Location:California, USA

Posted 22 November 2005 - 05:15 PM

Yeah what he said, lol





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users