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




[PHP] Processing Code created on the fly

2002-03-29 Thread Jonathan Duncan

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.

Next you will see a WHILE statement that should take the contents of the
those variables and evaluate those contents as if they had been hard-coded
in place of the variables.

So far, when I run the script as is it simply prints the contents of the
variables, which is raw PHP code, but does not process it.  The results is
that the raw PHP code that is in the variables doesn't get process, but is
output at text on the resulting HTML page.

Can anyone help me figure this out?  I would really appreciate it.

Thanks in advance,
Jonathan Duncan


begin 666 example.php
M/#\-E1H97-E('9AFEA8FQER!AF4]P=6QA=5D(%N9!AW-I9VYE
M9!I;B!A(9U;F-T:6]N.@T**%1H:7,:7,:G5S=!A;B!E%MQE+B 
M26X@86-T=6%L:71Y('1H97-E('9AFEA8FQEPT*87)E('!O'5L871E9!U
MVEN9R!O=AEB!M96%NRXI#0HM+2TM+2TM+2TM+2TM+2TM+2T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/]41#X-BH( ( 
M( ( ( ( ( )'1H969U;F-T:6]N+3YT86)L961A=$[#0H)0D)
M2 /%1$($%,24=./5PB8V5N=5R7(^70D;5]A;6]U;G0\+U1$/T*0D)
M0D(#Q41#X\02!(4D5/5PB7(;VYC;EC:SU(G=I;F1O=RYO5N*=P
M87EM96YTRYP:' G+=P87EV:65W)RPG=VED=]-3 P+AE:6=H=#TU,# L
M=]O;)ACUN;RQL;V-A=EO;CUN;RQD:7)E8W1OFEESUN;RQS=%T=7,]
M;F\LV-R;VQL8F%RSUN;RQR97-IF%B;4];F\L;65N=6)ACUN;RI.R!R
M971UFX@9F%LV5(B D;V5L:6YKW1Y;4^)'!A:61T:')U/]!/CPO5$0^
M#0H)0D)2 /%1$($%,24=./5PB8V5N=5R7(^70D86UO=6YT9'5E/]4
M1#X-D)0D)( \5$0^/$$@2%)%1CU(FUA:6QT;SHD96UA:6Q(B D;V5L
M:6YKW1Y;4^)5M86EL/]!/CPO5$0^#0H)0D)2 /%1$($%,24=./5PB
?8V5N=5R7(^)'1EFUS/]41#X\+U12/B([#0H_/``
`
end


-- 
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




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
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
?
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 =  TD$account/TD
   TD$service/TD;



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 .= TR CLASS=\$oddoreven\
   TD ALIGN=\center\A
HREF=\editaccount.php?id=$idedit=yes\image/A/TD
*  $thefunction-tabledata;
   TD ALIGN=\center\\$$m_amount/TD
   TDA HREF=\somefile.php\$paidthru/A/TD
   TD ALIGN=\center\\$$amountdue/TD
   TDA HREF=\mailto:$email\; $oelinkstyle$email/A/TD
   TD ALIGN=\center\$terms/TD/TR;
?



-- 
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 =  TD$account/TD
TD$service/TD;



 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 .= TR CLASS=\$oddoreven\
TD ALIGN=\center\A
 HREF=\editaccount.php?id=$idedit=yes\image/A/TD
 *  $thefunction-tabledata;
TD ALIGN=\center\\$$m_amount/TD
TDA HREF=\somefile.php\$paidthru/A/TD
TD ALIGN=\center\\$$amountdue/TD
TDA HREF=\mailto:$email\; $oelinkstyle$email/A/TD
TD ALIGN=\center\$terms/TD/TR;
 ?

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

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 =  TD$account/TD
 TD$service/TD;
 
 
 
  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 .= TR CLASS=\$oddoreven\
 TD ALIGN=\center\A
  HREF=\editaccount.php?id=$idedit=yes\image/A/TD
  *  $thefunction-tabledata;
 TD ALIGN=\center\\$$m_amount/TD
 TDA HREF=\somefile.php\$paidthru/A/TD
 TD ALIGN=\center\\$$amountdue/TD
 TDA HREF=\mailto:$email\; $oelinkstyle$email/A/TD
 TD ALIGN=\center\$terms/TD/TR;
  ?

 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 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:

   ?

   $a = 3;
   $b = 4;
   $c = \$a+=\$b;;
   eval($c);
   print $a;

   ?

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 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:

?php
$doo = $doo = 'dah';; # $
eval($doo);
echo Doo is $doobr;
?

Whereas this does:

?php
$doo = '$doo = \'dah\';';
eval($doo);
echo Doo is $doobr;
?



-- 
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