eval'

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ankur Gupta

    eval'


    I am retrieving the following string from the database.

    " and upper(gsa_templ ate_data_header ) >= '".$start_selec tion."' and upper(gsa_templ ate_data_header )
    <= '".$end_selecti on."' order by upper(gsa_templ ate_data_header ) asc"

    What I want to do is, replace the $start_selectio n 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_conditi ons = " and upper(gsa_templ ate_data_header ) >= '.\$start_selec tion.' and
    upper(gsa_templ ate_data_header ) <= '.\$end_selecti on.'
    order by upper(gsa_templ ate_data_header ) asc";

    $new_middle_con ditions = "";
    $tok = strtok($middle_ conditions,".") ;
    while ($tok) {
    if (strstr($tok, "$")==true)
    {
    eval ("$new_middle_c onditions .=".$tok.";") ;
    }
    else
    {
    $new_middle_con ditions .= $tok;
    }
    $tok = strtok(".");
    }

    if ($middle_condit ions != "")
    $middle_conditi ons = $new_middle_con ditions;


    Thanks,

    --
    -Ankur Gupta
  • Tom Thackrey

    #2
    Re: eval'


    On 11-Nov-2003, Ankur Gupta <agupta@cc.gate ch.edu> wrote:
    [color=blue]
    > $middle_conditi ons = " and upper(gsa_templ ate_data_header ) >=
    > '.\$start_selec tion.' and
    > upper(gsa_templ ate_data_header ) <= '.\$end_selecti on.'
    > order by upper(gsa_templ ate_data_header ) asc";
    >
    > $new_middle_con ditions = "";
    > $tok = strtok($middle_ conditions,".") ;
    > while ($tok) {
    > if (strstr($tok, "$")==true)
    > {
    > eval ("$new_middle_c onditions .=".$tok.";") ;
    > }
    > else
    > {
    > $new_middle_con ditions .= $tok;
    > }
    > $tok = strtok(".");
    > }
    >
    > if ($middle_condit ions != "")
    > $middle_conditi ons = $new_middle_con ditions;[/color]

    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_con ditions was
    replaced in the string giving you the eval error.

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

    --
    Tom Thackrey

    tom (at) creative (dash) light (dot) com
    do NOT send email to jamesbutler@wil lglen.net (it's reserved for spammers)

    Comment

    Working...