By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,101 Members | 1,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,101 IT Pros & Developers. It's quick & easy.

eval'

P: n/a

I am retrieving the following string from the database.

" and upper(gsa_template_data_header) >= '".$start_selection."' and upper(gsa_template_data_header)
<= '".$end_selection."' order by upper(gsa_template_data_header) asc"

What I want to do is, replace the $start_selection and $end_selection with the values in code.

I am doing this with the following code and it complains on call to eval. Can someone point out the error?
$middle_conditions = " and upper(gsa_template_data_header) >= '.\$start_selection.' and
upper(gsa_template_data_header) <= '.\$end_selection.'
order by upper(gsa_template_data_header) asc";

$new_middle_conditions = "";
$tok = strtok($middle_conditions,".");
while ($tok) {
if (strstr($tok, "$")==true)
{
eval ("$new_middle_conditions .=".$tok.";");
}
else
{
$new_middle_conditions .= $tok;
}
$tok = strtok(".");
}

if ($middle_conditions != "")
$middle_conditions = $new_middle_conditions;
Thanks,

--
-Ankur Gupta
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

On 11-Nov-2003, Ankur Gupta <ag****@cc.gatech.edu> wrote:
$middle_conditions = " and upper(gsa_template_data_header) >=
'.\$start_selection.' and
upper(gsa_template_data_header) <= '.\$end_selection.'
order by upper(gsa_template_data_header) asc";

$new_middle_conditions = "";
$tok = strtok($middle_conditions,".");
while ($tok) {
if (strstr($tok, "$")==true)
{
eval ("$new_middle_conditions .=".$tok.";");
}
else
{
$new_middle_conditions .= $tok;
}
$tok = strtok(".");
}

if ($middle_conditions != "")
$middle_conditions = $new_middle_conditions;


Your code would work if you change the eval to the following:
eval ("\$new_middle_conditions .=".$tok.";");
because you weren't escaping the $ the variable $new_middle_conditions was
replaced in the string giving you the eval error.

However, you could also replace all of your code with
eval("\$middle_conditions = \"$middle_conditions\";");
The eval can process the whole string at once, there's no need for you to
parse it.

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.