Re: [PHP] Processing Code created on the fly

2002-04-01 Thread Erik Price


On Friday, March 29, 2002, at 11:39  PM, Jonathan Duncan wrote:

> I have read the page for eval on php.net
> several times as well as the very helpful examples, but whenever I use 
> eval,
> it just prints out the same stuff.  By same stuff I mean wether I use 
> eval
> or just the variable by itself it just prints out the contents of the
> variable.  In the web page source it looks as if the contents were 
> merely
> echoed because it still has the $'s and variable names.  Any other 
> ideas or
> examples on how to implement eval on this?

eval() can let your variable contain PHP code in addition to simple text 
or HTML.  That's what makes it different from just "echoing back the 
text".  So you could do

$print_statement = "print('test');";

eval($print_statement);
// the output is "test", not "print('test');"

I just learned this function myself.


HTH,

Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Processing Code created on the fly

2002-03-29 Thread Jason Wong

On Saturday 30 March 2002 12:39, Jonathan Duncan wrote:
> Yeah, I have played with the eval function a bit, but it didn't seem to
> help much.  Then again, I haven't ever used the eval function before so I
> may not know how to properly implement it.  I have read the page for eval
> on php.net several times as well as the very helpful examples, but whenever
> I use eval, it just prints out the same stuff.  By same stuff I mean wether
> I use eval or just the variable by itself it just prints out the contents
> of the variable.  In the web page source it looks as if the contents were
> merely echoed because it still has the $'s and variable names.  Any other
> ideas or examples on how to implement eval on this?

Well one thing you shouldn't do is use double-quotes when assigning strings 
for later evaluation, particularly when they contain 'variables'.

Thus this does NOT work:

";
?>

Whereas this does:

";
?>



-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk

/*
To program is to be.
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Processing Code created on the fly

2002-03-29 Thread Miguel Cruz

On Fri, 29 Mar 2002, Jonathan Duncan wrote:
> Yeah, I have played with the eval function a bit, but it didn't seem to
> help much.  Then again, I haven't ever used the eval function before so
> I may not know how to properly implement it.  I have read the page for
> eval on php.net several times as well as the very helpful examples, but
> whenever I use eval, it just prints out the same stuff.  By same stuff I
> mean wether I use eval or just the variable by itself it just prints out
> the contents of the variable.  In the web page source it looks as if the
> contents were merely echoed because it still has the $'s and variable
> names.  Any other ideas or examples on how to implement eval on this?

You might want to think carefully about what you're trying to achieve
(after looking at your code, I certainly don't have the faintest idea, nor
do I get why it can't be accomplished using functions). eval() is usually
a last-ditch measure.

In any case, here's an example of how to use it:

   

Note that you have to pay a lot of attention to which dollar signs you 
escape and which you don't. With sufficiently complicated substitutions 
you can end up with a mess of dollar signs and backslashes that will give 
you a nosebleed.

miguel


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Processing Code created on the fly

2002-03-29 Thread Jonathan Duncan

Yeah, I have played with the eval function a bit, but it didn't seem to help
much.  Then again, I haven't ever used the eval function before so I may not
know how to properly implement it.  I have read the page for eval on php.net
several times as well as the very helpful examples, but whenever I use eval,
it just prints out the same stuff.  By same stuff I mean wether I use eval
or just the variable by itself it just prints out the contents of the
variable.  In the web page source it looks as if the contents were merely
echoed because it still has the $'s and variable names.  Any other ideas or
examples on how to implement eval on this?

Thanks for the help,
Jonathan Duncan


"Jason Wong" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]...
> On Saturday 30 March 2002 11:16, Jonathan Duncan wrote:
>
> >  > These variables are populated and assigned in a function:
> > (This is just an example.  In actuality these variables
> > are populated using other means.)
> > -
> > $othervars = " $service = $sqlresult['service'];
> >  $m_amount = $sqlresult['m_amount'];
> >  $paidthru = $sqlresult['paidthru'];
> >  $amountdue = $sqlresult['amountdue'];";
> >
> > $tabledata = " $account
> >$service";
> >
> >
> >
> > This is file that calls the above function:
> > (The lines with the *s are supposed to take
> > the data from the variables and then process
> > them as if they were part of the code.)
> > 
> > while ($sqlresult = mysql_fetch_array($result)) {
> >  $id = $sqlresult['id'];
> >  $account = $sqlresult['account'];
> > *$thefunction->othervars;
> >  $email = $sqlresult['email'];
> >  $terms = $sqlresult['terms'];
> >  $account_list .= "
> > > HREF=\"editaccount.php?id=$id&edit=yes\">image
> > *  $thefunction->tabledata;
> >\$$m_amount
> >$paidthru
> >\$$amountdue
> >mailto:$email\"; $oelinkstyle>$email
> >$terms";
> > ?>
>
> You need to check out the eval() function.
>
>
>
> --
> Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
>
> /*
> The real trouble with reality is that there's no background music.
> */



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Processing Code created on the fly

2002-03-29 Thread Jason Wong

On Saturday 30 March 2002 11:16, Jonathan Duncan wrote:

>  These variables are populated and assigned in a function:
> (This is just an example.  In actuality these variables
> are populated using other means.)
> -
> $othervars = " $service = $sqlresult['service'];
>  $m_amount = $sqlresult['m_amount'];
>  $paidthru = $sqlresult['paidthru'];
>  $amountdue = $sqlresult['amountdue'];";
>
> $tabledata = " $account
>$service";
>
>
>
> This is file that calls the above function:
> (The lines with the *s are supposed to take
> the data from the variables and then process
> them as if they were part of the code.)
> 
> while ($sqlresult = mysql_fetch_array($result)) {
>  $id = $sqlresult['id'];
>  $account = $sqlresult['account'];
> *$thefunction->othervars;
>  $email = $sqlresult['email'];
>  $terms = $sqlresult['terms'];
>  $account_list .= "
> HREF=\"editaccount.php?id=$id&edit=yes\">image
> *  $thefunction->tabledata;
>\$$m_amount
>$paidthru
>\$$amountdue
>mailto:$email\"; $oelinkstyle>$email
>$terms";
> ?>

You need to check out the eval() function.



-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk

/*
The real trouble with reality is that there's no background music.
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Processing Code created on the fly

2002-03-29 Thread Jonathan Duncan

Jason,

That is a good point and that being the case, following is my code.

Thanks,
Jonathan Duncan
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
$account
   $service";



This is file that calls the above function:
(The lines with the *s are supposed to take
the data from the variables and then process
them as if they were part of the code.)

while ($sqlresult = mysql_fetch_array($result)) {
 $id = $sqlresult['id'];
 $account = $sqlresult['account'];
*$thefunction->othervars;
 $email = $sqlresult['email'];
 $terms = $sqlresult['terms'];
 $account_list .= "
   image
*  $thefunction->tabledata;
   \$$m_amount
   $paidthru
   \$$amountdue
   mailto:$email\"; $oelinkstyle>$email
   $terms";
?>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Processing Code created on the fly

2002-03-29 Thread Jason Wong

On Saturday 30 March 2002 05:32, Jonathan Duncan wrote:
> I am trying to create an HTML Table which has TH headers which are
> different depending upon the link clicked to access the page.  Also, the
> content of the TD's below the headers would be different depending on the
> headers and depending on the link clicked.
>
> I have sorted out many of the details, but one eludes me.  Attached is an
> example that I have created to try to prove my point.  In it you will first
> see two variables that have been created inside of a function.  The
> function is called with certain values and these variables are created and
> populated with PHP code that needs to be evaluated at a point later in the
> file that calls the function.

I suggest that you post again and include your code inline with your post 
rather than attaching it. 

People are lazy and many (me included) couldn't/wouldn't be bothered to save 
your attachment and open up their text editor/viewer to read it.


-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk

/*
It is always the best policy to tell the truth, unless, of course,
you are an exceptionally good liar.
-- Jerome K. Jerome
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php