Web Design and Development Forums

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.


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

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old Apr 17th, 2008, 19:44   #1 (permalink)
Junior Member
 
Join Date: Apr 2006
Location: UK
Posts: 14
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!
Sagaris is offline  
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
Rate This Thread
Rate This Thread:

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



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 11:02.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59