Declaring variables in eval'd code

This is a discussion on "Declaring variables in eval'd code" within the PHP Forum section. This forum, and the thread "Declaring variables in eval'd code are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Apr 17th, 2008, 19:44
Junior Member
Join Date: Apr 2006
Location: UK
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Declaring variables in eval'd code

Hi there,

I am trying to find an appropiate method by which I can store php code in a database, and then parse the code when it is retrieved from the database using PHP.

Eval seems to be the way to go (need to have a look at the security implications first), but I am just trying to get a quick example working. What is stumping me at the moment is being able to include the declaration of PHP variables in the string stored in the database. Escaping the $ in front of the variable declarations was suggested in some eval tutorials but to no avail.

Here is my test code

Code: Select all
    $php = "<? \$1 = abc; ?>this is the text with php code in it.  <? echo \$1; ?>";
  
    ob_start();

    eval(" ?>" . $php . "<? ");

    $output = ob_get_contents();

    ob_end_clean();

    echo $output;
and this is the error I am receiving

Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in /hermes/web09/b1130/pow.blah/htdocs/eval-test.php(33) : eval()'d code on line 1

If I change the value of the $php variable to

Code: Select all
$php = "This is the text with php code in it.  <? echo date('H:M:S'); ?>";
The PHP parses fine.

If anybody can shed some light on this I would be really grateful. Alternatively if you can think of a more suitable method for getting PHP out of a database and then parsed fire away!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
code behind code doesnt work skat ASP.NET Forum 4 Feb 18th, 2008 10:05
live search code and styleswitcher code hebel JavaScript Forum 0 May 12th, 2007 06:16
Variables!! bionics PHP Forum 6 Apr 25th, 2006 15:39
Can somebody give me the code to hide the source code? renren JavaScript Forum 7 Mar 7th, 2006 12:27
Get URL and use variables JamieH PHP Forum 2 Jan 1st, 2006 03:13


All times are GMT. The time now is 15:27.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42