473,805 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

eval problem

Hi,
I have to eval a string stored in a variable, but it's not working.
code:
___

function ee($s)
{
return $s;
}

$v="e(\"name\") ";

eval("$stri=$v; ");
echo $stri;
___

By using eval I want to eval $v and get the result returned by ee
stored in $stri. How woul you do?

Sep 23 '06 #1
5 1512
iulian.ilea wrote:
By using eval I want to eval $v and get the result returned by ee
stored in $stri. How woul you do?
Why use eval at all?

function ee($s) { return $s; }
$str = ee("Bob");
print $str;
JW
Sep 24 '06 #2

Janwillem Borleffs wrote:
iulian.ilea wrote:
By using eval I want to eval $v and get the result returned by ee
stored in $stri. How woul you do?

Why use eval at all?

function ee($s) { return $s; }
$str = ee("Bob");
print $str;
JW
Thanks, but what I wrote above is just an example. I take the variable
that must be eval'd from an sql table.

Sep 24 '06 #3
iulian.ilea said the following on 24/09/2006 12:54:
Janwillem Borleffs wrote:
>iulian.ilea wrote:
>>function ee($s)
{
return $s;
}

$v="e(\"name\ ")";

eval("$stri=$ v;");
echo $stri;
>>By using eval I want to eval $v and get the result returned by ee
stored in $stri. How woul you do?
Why use eval at all?

function ee($s) { return $s; }
$str = ee("Bob");
print $str;

Thanks, but what I wrote above is just an example. I take the variable
that must be eval'd from an sql table.
This leads to a further question: Why does your database contain PHP
code? This goes against normal practices of both database and PHP
design. You may be aware of the popular quotation:

"If eval() is the answer, you're almost certainly asking the wrong
question."

i.e. there's probably a better, safer, more programmatic way of doing
what you're doing.
However, the answer to your original problem is that if you want the
string literal '$stri', you must escape the $ character, i.e.:

eval("\$stri = $v;");

Otherwise the value of $stri is substituted into the expression to be
evaluated (and presumably at this point $stri doesn't exist).
--
Oli
Sep 24 '06 #4
iulian.ilea wrote:
>
By using eval I want to eval $v and get the result returned by ee
stored in $stri. How woul you do?
Exactly the way its written in the manual (http://uk2.php.net/eval)

$v = 'e("name")';
$v="\$stri = " . $v . ";";
eval($v);
print $stri;

Eval (and storing code in a database) is very dangerous unless you know what
you're doing - and anyone who know what they were doing would RTFM first.
You have not done that therefore we must assume you don't know what you are
doing.

And if you did know what you were doing you would be trying very hard to
avoid the scenario where this is the solution.

C.
Sep 24 '06 #5
"iulian.ile a" <iu*********@gm ail.comwrote:
>
I have to eval a string stored in a variable, but it's not working.
code:
___

function ee($s)
{
return $s;
}

$v="e(\"name\" )";

eval("$stri=$v ;");
echo $stri;
___

By using eval I want to eval $v and get the result returned by ee
stored in $stri. How woul you do?
Well, for one thing, I would not try to call a function called "e" when I
had named the function "ee".
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Sep 25 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
3800
by: Stuart | last post by:
why won't the following work for(var i=0;i<pics;i++){ eval('img'+i) = new Image(wth,hgt) eval('img'+i+'.src') = 'http://www.mypics/'+i+'1.gif' } basically I am trying to create a numer of placeholders with thier associated imgages!
7
4112
by: Reply Via Newsgroup | last post by:
This might sound sad... someone requesting a disertation on the 'eval' statement... but... I've been reading someone else's post - they had a huge calander like script and a handful of folk cursed the script and special attention was thrown at the fact the script used eval alot. I don't use eval alot in my scripts - but I do use it - and since I always out to learn more / improve my javascript skills, I'm curious why something I thought...
6
2121
by: Roebie | last post by:
Hi everyone, I'm having some weird problem with evaluating the continue statement. Within a for loop I'm trying to evaluate a string (generated somewhere earlier) which basically has the continue statement in it. IE6 seems to have major problems with that as it generates an error "Can't have 'continue' outside of loop". Does anyone know why and/or have a workaround? I haven't tried any other browser since this one is the only one...
18
3165
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My question is what happens to the dynamically created assembly when the method is done running? Does GC take care of it? Or is it stuck in RAM until the ASP.Net process is recycled? This code executes pretty frequently (maybe 4 times per transaction) and...
8
1656
by: santel_helvis | last post by:
Hi, Here is my code. function CallDisplay() { nodeobj=new mynode(); x="displayId("+nodeobj+")"; eval(x);
3
1924
by: Pauljh | last post by:
Hi All, I'm running some javascript over a server side generated web page and have multiple generated empty select statements, that I want to populate when the page is loaded. As HTML doesn't do arrays each select is individually named withe MySelecti where i is an incremental from 1. I know all my variables are correct (i, OptionsCount) and my arrays of MyValues and MyDescription's exist for multiple enteries and if I bring out an...
6
5933
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with or without parms. I know that any function that is passed to Eval() must be declared Public. It can be a Sub or Function, as long as it's Public. I even have it where the "function" evaluated by Eval can be in a form (class) module or in a standard...
5
6638
by: wendallsan | last post by:
Hi all, I'm running into a situation where it seems that JS stops executing as soon as I call an eval in my script. I have an Ajax.Request call to a PHP page that builds a JS object and returns it as the responseText. I want to attach that object to the document (or anywhere else that would allow me to access it later), and to do that, I THINK I need to eval it because it's just a string otherwise. My problem is as soon as I execute a...
12
3492
by: Bill Mill | last post by:
Hello all, I want to have a user able to eval code in a text box. However, if he accidentally types "while(1) { i=0; }" and hits "run", I also want him to be able to hit a stop button such that his browser does not go into an infinite, soul-crushing, interface-locking loop. The stop button would not need to be instantly responsive, but of course the more responsive the better. Short of writing a javascript-in-javascript interpreter,...
16
3934
by: Fett | last post by:
I am creating a program that requires some data that must be kept up to date. What I plan is to put this data up on a web-site then have the program periodically pull the data off the web-site. My problem is that when I pull the data (currently stored as a dictionary on the site) off the site, it is a string, I can use eval() to make that string into a dictionary, and everything is great. However, this means that I am using eval() on...
0
9716
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10607
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10359
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5541
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4317
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3843
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.