473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Evaluate a string as PHP code

150 100+
I need to Evaluate big chunk of a string as PHP code ,that code I'm getting it from the DB and publish it's data into page this page i want to deal with it as normal PHP page to include it into other pages ,how can i do that?
This page (code.php) that get the code from DB:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //that code for explanation not the real code
  3. mysql_connect('localhost','root','');
  4. mysql_select_db('testing');
  5.  
  6. $result = mysql_query('SELECT * FROM PHP');
  7. while($row = mysql_fetch_assoc($result)){
  8.     echo $row['CODE'].";\n";
  9. }
  10. ?>
Here i need to include it as PHP page not as string:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include('code.php');
  3. ?>
Dec 3 '08 #1
4 3006
Dormilich
8,658 Expert Mod 8TB
try PHP: eval - Manual for the code evaluation.

regards
Dec 3 '08 #2
smartic
150 100+
i need to Evaluate all the page code like:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. eval(include('code.php'));
  3. ?>
put this give me an error is there is another way?
Dec 3 '08 #3
Dormilich
8,658 Expert Mod 8TB
eval() expects a string as input but include() doesn't have any return value, whatsoever. try to import the file as string, e.g. PHP: fopen - Manual and PHP: file_get_contents - Manual

regards
Dec 3 '08 #4
Atli
5,058 Expert 4TB
Try creating a function that loads and eval()s the code from the database. Then simply include a file with that function into your pages and call the function where it is needed.

Like:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. # executeFunction.php
  3. function executeCode($codeID)
  4. {
  5.   $sql = "SELECT code FROM codeTable WHERE codeID = $codeID";
  6.   $result = mysql_query($sql);
  7.  
  8.   if(mysql_num_rows($result) > 0) {
  9.     $row = mysql_fetch_assoc($result);
  10.     eval($row['code']);
  11.   }
  12. }
  13. ?>
  14.  
Expand|Select|Wrap|Line Numbers
  1. # whatever.php
  2. include("executeFunction.php");
  3.  
  4. for($i = 0; $i < 10; $i++) {
  5.   executeCode($i);
  6. }
  7.  
Get my thinking?
Dec 3 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John Spiegel | last post by:
Hi all, Is it possible to have an uncompiled C# expression evaluated at runtime? I'd like to store an expression within an XML file then evaluate it when the time comes, something like: ...
1
by: David Laub | last post by:
I have no problems running the following dynamic XPath evaluator form MSXSL: <msxsl:script implements-prefix="dyn" language="jscript"> evaluate(context, expression) { return...
13
by: Zeng | last post by:
Hello, Please help!!! I've been stuck on this issue for months. I just wonder if there is a way to programmatically evaluate expression strings such as ( ( 3 + 5 ) / 2 ) > 4 --> this...
2
by: Brad Smith | last post by:
I'm trying to clean up strings in a web form before I plug the fields into a database. Lots of folks like to leave caps lock key on and yell their form entries. I can figure out how to change...
13
by: TJS | last post by:
How can I evaluate this string in vb.net " Dim submenu0 As New skmMenu.MenuItem('Home', '') " I have tried this with skmmenu as a reference in the compile command but assembly will not...
15
by: Phlip | last post by:
Javascripters: I have an outer page and an inner iframe. The outer page calculates some javascript, and wants the inner frame to run it. The inner frame should hit a page on the same (private)...
2
kadghar
by: kadghar | last post by:
Many people asks if there is a way to write a mathematical expression, writen as a string in a text box, so they can do something like: sub something_click() textbox2.text=eval(textbox1.text)...
2
by: yarborg | last post by:
This is kind of a weird one and hard to find answers online because of the format of the question. Essentially I want to be able to have a string that looks like this "True AND True AND True" and...
1
by: aitia | last post by:
this the code. i used ECLIPSE to run this.. it has some codes smells that i can't seem to figure out.. can any one help? import java.io.*; import java.util.*; public class Postfix { private...
1
by: Monusonu | last post by:
Hi Expert, I am trying to get the value from excel formula cell using POI. My code works fine for less complex formula cells, but fails or returns error code for complex formula cells. Following...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.