[PHP] Re: eval and HEREDOC

2010-07-20 Thread David Robley
Sorin Buturugeanu wrote:

 Hello,
 
 I am having trouble with a part of my templating script. I'll try to
 explain:
 
 The template itself is HTML with PHP code inside it, like:
 
 div?=strtoupper($user['name']);?/div
 
 And I have the following code as part of the templating engine:
 
 $template = file_get_contents($file);
 $template = return TEMPLATE\n.$template.\nTEMPLATE;\n;
 $template = eval($template);
 
 The problem is that the eval() HEREDOC combination gives the following
 output:
 
 ?=strtoupper(Array['time']);?
 
 If in the HTML file (template) I use
 
 div?=strtoupper({$user['name']});?/div
 
 I get  ?=strtoupper(username);? as an output.
 
 I have tried closing the php tag like this:
 
 $template = return TEMPLATE\n?.$template.\nTEMPLATE;\n;
 
 but the extra ? only gets outputed as HTML.
 
 This is my first post to this mailing list, so I great you all and thank
 you for any kind of solution to my problem.
 
 Thank you!

Possibly your php environment has short-tags turned off.


Cheers
-- 
David Robley

To save trouble later, Joe named his cat Roadkill Fred
Today is Boomtime, the 56th day of Confusion in the YOLD 3176. 


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



[PHP] Re: eval() question

2004-04-21 Thread Jason Barnett
Orangehairedboy wrote:

I would like to use eval() to evaluate another PHP file and store the output
of that file in a string.
Personally, I try to avoid using eval().  It can be very useful, but 
there are also potential security issues depending on your setup.  Based 
on what you said in another post, suppose someone can execute an INSERT 
command for your database and replaces the code for colors.php?

So, let's say, for example, that I have a file called colors.php which
contains this:
pColors: ? echo Red, Yellow, Green, Blue; ?/p
You might use return instead.  Something like:
/** colors.php */
?php
$colors = array('Red', 'Yellow', 'Green', 'Blue');
return $colors;
?
/** another file */
?php
$colors = include_once 'colors.php';

?

This works because included files can use return to return values.
http://www.php.net/return
Then, in another file, I have this:

$file = file_get_contents( colors.php );
$colors = eval( $file );
I'm having problems getting $file into $colors. How can I do this?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: eval

2003-08-01 Thread Bogdan Stancescu
You can put whatever you want in eval:

?
  $foo='foo';
  $bar='bar';
  echo(foo is $foo; bar is $bar);
  $myCode='$foo=checking eval statements; ';
  $myCode.='$bar=str_replace( ,--,$foo);';
  eval($myCode);
  echo(foo is $foo; bar is $bar);
?
You could even do this:

?
  $foo='$i++;';
  $bar='eval($foo);';
  $i=1;
  eval($foo);
  echo(i=$i);
  eval($bar);
  echo(i=$i);
?
HTH

Bogdan

Decapode Azur wrote:

Is it possible to put PHP code in eval ?
Or just vars ?
?php

$string = 'The result of ?php $a=2; $b=3; $c=$a+$b; echo $a + $b is $c; 
?';

eval ($string);

?


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


[PHP] Re: Eval var from query

2003-07-14 Thread Shawn McKenzie
eval($data)

returns Parse error: parse error, unexpected T_STRING in
C:\apps\apache2\htdocs\test\query.php(23) : eval()'d code on line 1

Thanks!
Shawn

Shawn McKenzie [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 How can I evaluate a var that is from a text field of a database?
Example:

 MySQL field `name` = hi my name is $name

 In my script I have:

 $name = Shawn;

 After fetching a query result as an associative array I have the contents
of
 the `name` field in $data

 If I echo $data I get:  hi my name is $name

 I would like to get:  hi my name is Shawn

 TIA,
 Shawn





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



Re: [PHP] Re: Eval var from query

2003-07-14 Thread Kevin Stone
The string you send to eval() must be valid PHP code.  So try this..

eval( 'echo '.$data.';');

- Kevin


- Original Message -
From: Shawn McKenzie [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, July 14, 2003 1:15 PM
Subject: [PHP] Re: Eval var from query


 eval($data)

 returns Parse error: parse error, unexpected T_STRING in
 C:\apps\apache2\htdocs\test\query.php(23) : eval()'d code on line 1

 Thanks!
 Shawn

 Shawn McKenzie [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  How can I evaluate a var that is from a text field of a database?
 Example:
 
  MySQL field `name` = hi my name is $name
 
  In my script I have:
 
  $name = Shawn;
 
  After fetching a query result as an associative array I have the
contents
 of
  the `name` field in $data
 
  If I echo $data I get:  hi my name is $name
 
  I would like to get:  hi my name is Shawn
 
  TIA,
  Shawn
 
 



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





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



Re: [PHP] Re: Eval var from query

2003-07-14 Thread Kevin Stone
I realized that may not make any sense.  Following up the eample relates to
your original query like this..

 MySQL field `name` = hi my name is $name
 In my script I have:
 $name = Shawn;

$data = 'hi my name is $name';
$code = 'echo '.$data.';';
$name = 'Shawn';
eval($code); // prints hi may name is Shawn.

Hope that makes it more clear.

- Kevin



- Original Message -
From: Kevin Stone [EMAIL PROTECTED]
To: PHP-GENERAL [EMAIL PROTECTED]
Sent: Monday, July 14, 2003 1:23 PM
Subject: Re: [PHP] Re: Eval var from query


 The string you send to eval() must be valid PHP code.  So try this..

 eval( 'echo '.$data.';');

 - Kevin


 - Original Message -
 From: Shawn McKenzie [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Monday, July 14, 2003 1:15 PM
 Subject: [PHP] Re: Eval var from query


  eval($data)
 
  returns Parse error: parse error, unexpected T_STRING in
  C:\apps\apache2\htdocs\test\query.php(23) : eval()'d code on line 1
 
  Thanks!
  Shawn
 
  Shawn McKenzie [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
   How can I evaluate a var that is from a text field of a database?
  Example:
  
   MySQL field `name` = hi my name is $name
  
   In my script I have:
  
   $name = Shawn;
  
   After fetching a query result as an associative array I have the
 contents
  of
   the `name` field in $data
  
   If I echo $data I get:  hi my name is $name
  
   I would like to get:  hi my name is Shawn
  
   TIA,
   Shawn
  
  
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 



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





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



Re: [PHP] Re: Eval var from query

2003-07-14 Thread Shawn McKenzie
Thanks Kevin!  That works great.  It outputs:  hi my name is Shawn

Now if I want to assign $data to another var, let's say $newdata and have it
eval the $name var inside of that.  How would that work?

Meaning I want to $newdata = hi my name is Shawn

Thanks!
Shawn

Kevin Stone [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 The string you send to eval() must be valid PHP code.  So try this..

 eval( 'echo '.$data.';');

 - Kevin


 - Original Message -
 From: Shawn McKenzie [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Monday, July 14, 2003 1:15 PM
 Subject: [PHP] Re: Eval var from query


  eval($data)
 
  returns Parse error: parse error, unexpected T_STRING in
  C:\apps\apache2\htdocs\test\query.php(23) : eval()'d code on line 1
 
  Thanks!
  Shawn
 
  Shawn McKenzie [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
   How can I evaluate a var that is from a text field of a database?
  Example:
  
   MySQL field `name` = hi my name is $name
  
   In my script I have:
  
   $name = Shawn;
  
   After fetching a query result as an associative array I have the
 contents
  of
   the `name` field in $data
  
   If I echo $data I get:  hi my name is $name
  
   I would like to get:  hi my name is Shawn
  
   TIA,
   Shawn
  
  
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 





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



Re: [PHP] Re: Eval var from query

2003-07-14 Thread Shawn McKenzie
Got it!

eval( '$newdata = '.$data.';');

Thanks!
Shawn

Shawn McKenzie [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Thanks Kevin!  That works great.  It outputs:  hi my name is Shawn

 Now if I want to assign $data to another var, let's say $newdata and have
it
 eval the $name var inside of that.  How would that work?

 Meaning I want to $newdata = hi my name is Shawn

 Thanks!
 Shawn

 Kevin Stone [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  The string you send to eval() must be valid PHP code.  So try this..
 
  eval( 'echo '.$data.';');
 
  - Kevin
 
 
  - Original Message -
  From: Shawn McKenzie [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Sent: Monday, July 14, 2003 1:15 PM
  Subject: [PHP] Re: Eval var from query
 
 
   eval($data)
  
   returns Parse error: parse error, unexpected T_STRING in
   C:\apps\apache2\htdocs\test\query.php(23) : eval()'d code on line 1
  
   Thanks!
   Shawn
  
   Shawn McKenzie [EMAIL PROTECTED] wrote in message
   news:[EMAIL PROTECTED]
How can I evaluate a var that is from a text field of a database?
   Example:
   
MySQL field `name` = hi my name is $name
   
In my script I have:
   
$name = Shawn;
   
After fetching a query result as an associative array I have the
  contents
   of
the `name` field in $data
   
If I echo $data I get:  hi my name is $name
   
I would like to get:  hi my name is Shawn
   
TIA,
Shawn
   
   
  
  
  
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
  
  
 
 





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



Re: [PHP] Re: Eval var from query

2003-07-14 Thread Kevin Stone
- Original Message -
From: Shawn McKenzie [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, July 14, 2003 1:51 PM
Subject: Re: [PHP] Re: Eval var from query


 Thanks Kevin!  That works great.  It outputs:  hi my name is Shawn

 Now if I want to assign $data to another var, let's say $newdata and have
it
 eval the $name var inside of that.  How would that work?

 Meaning I want to $newdata = hi my name is Shawn

 Thanks!
 Shawn

Umm.. well.. '$name' is a litteral inside the string until it is evaluated.
It doesn't matter if you make a copy of the variable, '$name' is still going
to be a litteral value.  So you'll have to eval() it exactly the same way
every time.  But maybe I can offer an alternative...

You look at this string and see a code evaluation problem.  I look at this
string and see a find and replace problem.  Consider useing str_replace()
to search for and replace '$name' as a template marker rather than a
variable to be evaluated..

$data = 'hi my name is $name';
$name = 'Shawn';
echo str_replace('$name', $name, $data);

This accomplishes exactly the same thing and it's a perfectly valid form.
Plus it's going to work on any string becuase you don't have to turn them
into PHP code first.

- Kevin



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



[PHP] Re: eval help

2003-03-03 Thread neko
note that the following php:

?php
/*
  eval testing
  SM 3/3/2003 1:28PM
*/

$name = Scott;
$arr[] = Dude;
$arr2[name] = Broness!;

echo($arr2['name']); // test

$str  = brHello, $name;
$str2 = brHello, $arr[0];
$str3 = brHello, $arr2['name'];

eval (\$evaldString = \$str\;);
echo $evaldString;

eval (\$evaldString = \$str2\;);
echo $evaldString;

eval (\$evaldString = \$str3\;);
echo $evaldString;

?

produces:

Broness!brHello, ScottbrHello, DudebrHello,

--

note that the last cannot be seen - I'm sure I'm almost there, but I have to
be able to reference an associative array.

Scott



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



Re: [PHP] Re: eval help

2003-03-03 Thread Dan Hardiker
Hi,

 $arr2[name] = Broness!;
..
 $str3 = brHello, $arr2['name'];
..
 eval (\$evaldString = \$str3\;);
 echo $evaldString;

Your almost there... just remember one very simple rule - if in doubt,
break out. Meaning, if you're having variable resolution issues, then just
break out of the string. Apply the following change to have happy dreams:

From:
 $str3 = brHello, $arr2['name'];

To:
 $str3 = brHello, .$arr2['name'];


-- 
Dan Hardiker [EMAIL PROTECTED]
ADAM Software  Systems Engineer
First Creative



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



Re: [PHP] Re: eval help

2003-03-03 Thread neko
Thanks Dan - I just worked this out before reading your solution! :)

$str4 = brHello, .$arr2['name'];

cheers and thanks to all - lets see how that goes within my framework now :)

neko



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



[PHP] Re: eval help

2003-03-03 Thread neko
Actually, I just realised that what I want to accomplish is different from
my example - the main issue is with scope:

?php
/*
  eval testing 3
  SM 33/3/2003 2:32PM
*/

func1();

function func1()
{
  echo(brwe're in the pipe, 5-5-5.);

  $str  = brHello, \$name;
  $str2 = brHello, \$arr[0];
  $str3 = brHello, \$arr2['name'];

  echo doEvalWithVarsInScope($str);
  echo doEvalWithVarsInScope($str2);
  echo doEvalWithVarsInScope($str3);
}

function doEvalWithVarsInScope($str)
{
  echo(brtrying to eval for str=$str);

  $name = Scott;
  $arr[] = Dude;
  $arr2[name] = Broness!;

  eval (\$evaldString = \$str\;);
  return $evaldString;
}

?

--

will produce:

we're in the pipe, 5-5-5.
trying to eval for str=
Hello, $name
Hello, Scott
trying to eval for str=
Hello, $arr[0]
Hello, Dude
trying to eval for str=
Hello, $arr2['name']
Hello,

--

any (more) help is greatly appreciated.

cheers,
neko



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



[PHP] Re: eval help

2003-03-03 Thread neko
?php
/*
  eval testing 3
  SM 33/3/2003 2:32PM
*/

define(NAME_TAG, name);
func1();

function func1()
{
  echo(brwe're in the pipe, 5-5-5.);

  $str  = brHello, \$name;
  $str2 = brHello, \$arr[0];
  $str3 = brHello, \$arr2[.NAME_TAG.];

  echo doEvalWithVarsInScope($str);
  echo doEvalWithVarsInScope($str2);
  echo doEvalWithVarsInScope($str3);
}

function doEvalWithVarsInScope($str)
{
  echo(brtrying to eval for str=$str and NAME_TAG:.NAME_TAG);

  $name = Scott;
  $arr[] = Dude;
  $arr2[NAME_TAG] = Broness!;

  eval (\$evaldString = \$str\;);
  return $evaldString;
}

?

--

produces:


we're in the pipe, 5-5-5.
trying to eval for str=
Hello, $name and NAME_TAG:name
Hello, Scott
trying to eval for str=
Hello, $arr[0] and NAME_TAG:name
Hello, Dude
trying to eval for str=
Hello, $arr2[name] and NAME_TAG:name
Hello, Broness!

--

done, but it's uglier than I was hoping :(



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



[PHP] Re: eval help

2003-03-03 Thread neko
ok - my latest in the eval saga is this:

I want to be able to eval a function call anywhere in the string supplied,
and the function call is not in scope when the string is defined.

So

-- somewhere in my code I wanted something like this:

$string = brtesting nodename: \$node-getName()
pagename:\$nodePageTags[.TAG_PAGENAME.];

-- where the code is evaled eventually, there is a $node object defined, so
the function call should work. Of course, that currently does not work :)

cheers,
neko



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



Re: [PHP] Re: eval()

2002-01-27 Thread Jason Wong

On Monday 21 January 2002 12:17, Alex Dowgailenko wrote:
 After getting very frustrated with arrays, I ended up using eval() in the
 following way:

 function top10() {
   $i = 0;
   $res = mysql_query(SELECT orders.pid, products.pid, orders.amount,
 products.pname FROM orders, products WHERE orders.uid!='' AND
 orders.pid=products.pid) or die(mysql_error());
   while (list($opid, $ppid, $amount, $pname) = mysql_fetch_row($res)) {
   $eval = '$temp['.$pname.'] = $temp['.$pname.'] + '.$amount.';';
   eval($eval);
   $i++;
   }
   arsort($temp);
   return $temp;
 }

If you're using php4.03+ you could try:

  while ($row = mysql_fetch_assoc($res) {
$temp[$row['pname']] = $row['pname'] + $row['amount'];
$i++;
  }



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

/*
Life is a sexually transmitted disease with 100% mortality.
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: eval()

2002-01-20 Thread Michael Waples

Kunal Jhunjhunwala wrote:
 
 Hey
 Does anybody know if its wise to use eval() ? I know Vbulletin uses it.. but
 there is something about it I just cant digest.. it seems to be a very
 powerfull function which can be very easily exploited... anyone else have
 any thoughts?
 Regards,
 Kunal

 Loading your templates into a database, pulling them out on every page
load and running eval() to run the code isn't the most efficient way to
do it.
Then running eval() inside a loop on that code isn't efficient either.

I think eval() is used this way by some people because they don't know
how to write files using php propely. So instead they just put it in a
database. You also completely miss out on getting the benefits of one of
the different php caching products.
For me a database is for storing data - not php code.
Vbulletin as an example of complete overuse of eval().

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: eval()

2002-01-20 Thread Kunal Jhunjhunwala

Hey,
I tend to agree with you. But what is the most effiecent way of using php
code in template files then? I am not going to move my templates to a
dbase.. thats for sure.
Regards,
Kunal Jhunjhunwala
- Original Message -
From: Michael Waples [EMAIL PROTECTED]
To: Kunal Jhunjhunwala [EMAIL PROTECTED]
Cc: php-list [EMAIL PROTECTED]
Sent: Sunday, January 20, 2002 5:51 PM
Subject: Re: eval()


 Kunal Jhunjhunwala wrote:
 
  Hey
  Does anybody know if its wise to use eval() ? I know Vbulletin uses it..
but
  there is something about it I just cant digest.. it seems to be a very
  powerfull function which can be very easily exploited... anyone else
have
  any thoughts?
  Regards,
  Kunal

  Loading your templates into a database, pulling them out on every page
 load and running eval() to run the code isn't the most efficient way to
 do it.
 Then running eval() inside a loop on that code isn't efficient either.

 I think eval() is used this way by some people because they don't know
 how to write files using php propely. So instead they just put it in a
 database. You also completely miss out on getting the benefits of one of
 the different php caching products.
 For me a database is for storing data - not php code.
 Vbulletin as an example of complete overuse of eval().




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Re: eval()

2002-01-20 Thread Nick Wilson

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


* On 20-01-02 at 13:26 
* Kunal Jhunjhunwala said

 Hey,
 I tend to agree with you. But what is the most effiecent way of using php
 code in template files then? I am not going to move my templates to a
 dbase.. thats for sure.

The point of templates is to seperate code from presentation and
content. Your template should only contain html/js, and your code should
be in the script that calls the template. Why not databases? That way
you achieve a proper 3 tier structure that's easy to maintain.

- -- 

Nick Wilson

Tel:+45 3325 0688
Fax:+45 3325 0677
Web:www.explodingnet.com



-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.6 (GNU/Linux)

iD8DBQE8SrjEHpvrrTa6L5oRAoXnAJ9mq+aZx44O3suRenE035hxFPXscgCgncwt
tsmQSf7IkpJ4V9gCqtfepFU=
=RBPj
-END PGP SIGNATURE-

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: eval()

2002-01-20 Thread Michael Waples

Kunal Jhunjhunwala wrote:
 
 Hey,
 I tend to agree with you. But what is the most effiecent way of using php
 code in template files then? I am not going to move my templates to a
 dbase.. thats for sure.
 Regards,
 Kunal Jhunjhunwala

well for looping through the results of a sql query where you'd want to
print out some html -
to do that you could -
a include a file inside a loop
b run eval on some code from a database
c run a function

I find c to be the most efficient
eg

function thread($sql_arra0
{
echo 'name - '. $sql_array['name'] .';
}

then inside of loop

thread($sql_array);

works a lot quicker than the other two methods.

I don't see how you can avoid putting php code in templates because you
need to put $var in there some way so you can print out the variable. So
if it's in a database it needs some eval() done on it.
I really can't see the point in querying a database to pull out template
data. Templates usually don't change very often at all and querying a
database to pull out unchanged template data is waste of cpu and memory
resources.


 
 
  Kunal Jhunjhunwala wrote:
  
   Hey
   Does anybody know if its wise to use eval() ? I know Vbulletin uses it..
 but
   there is something about it I just cant digest.. it seems to be a very
   powerfull function which can be very easily exploited... anyone else
 have
   any thoughts?
   Regards,
   Kunal
 
   Loading your templates into a database, pulling them out on every page
  load and running eval() to run the code isn't the most efficient way to
  do it.
  Then running eval() inside a loop on that code isn't efficient either.
 
  I think eval() is used this way by some people because they don't know
  how to write files using php propely. So instead they just put it in a
  database. You also completely miss out on getting the benefits of one of
  the different php caching products.
  For me a database is for storing data - not php code.
  Vbulletin as an example of complete overuse of eval().
 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Re: eval()

2002-01-20 Thread Kunal Jhunjhunwala

 I don't see how you can avoid putting php code in templates because you
 need to put $var in there some way so you can print out the variable. So
 if it's in a database it needs some eval() done on it.

You could html comment lines?? I tried this.. but it would only consider the
first and the last match of the ereg.. not the in-between ones :(

 I really can't see the point in querying a database to pull out template
 data. Templates usually don't change very often at all and querying a
 database to pull out unchanged template data is waste of cpu and memory
 resources.

Agreed.

Regards,
Kunal Jhunjhunwala
- Original Message -
From: Michael Waples [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Sunday, January 20, 2002 6:39 PM
Subject: [PHP] Re: eval()


 Kunal Jhunjhunwala wrote:
 
  Hey,
  I tend to agree with you. But what is the most effiecent way of using
php
  code in template files then? I am not going to move my templates to a
  dbase.. thats for sure.
  Regards,
  Kunal Jhunjhunwala

 well for looping through the results of a sql query where you'd want to
 print out some html -
 to do that you could -
 a include a file inside a loop
 b run eval on some code from a database
 c run a function

 I find c to be the most efficient
 eg

 function thread($sql_arra0
 {
 echo 'name - '. $sql_array['name'] .';
 }

 then inside of loop

 thread($sql_array);

 works a lot quicker than the other two methods.

 I don't see how you can avoid putting php code in templates because you
 need to put $var in there some way so you can print out the variable. So
 if it's in a database it needs some eval() done on it.
 I really can't see the point in querying a database to pull out template
 data. Templates usually don't change very often at all and querying a
 database to pull out unchanged template data is waste of cpu and memory
 resources.



 
   Kunal Jhunjhunwala wrote:
   
Hey
Does anybody know if its wise to use eval() ? I know Vbulletin uses
it..
  but
there is something about it I just cant digest.. it seems to be a
very
powerfull function which can be very easily exploited... anyone else
  have
any thoughts?
Regards,
Kunal
  
Loading your templates into a database, pulling them out on every
page
   load and running eval() to run the code isn't the most efficient way
to
   do it.
   Then running eval() inside a loop on that code isn't efficient either.
  
   I think eval() is used this way by some people because they don't know
   how to write files using php propely. So instead they just put it in a
   database. You also completely miss out on getting the benefits of one
of
   the different php caching products.
   For me a database is for storing data - not php code.
   Vbulletin as an example of complete overuse of eval().
  
  

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Re: eval()

2002-01-20 Thread Alex Dowgailenko

After getting very frustrated with arrays, I ended up using eval() in the
following way:

function top10() {
$i = 0;
$res = mysql_query(SELECT orders.pid, products.pid, orders.amount,
products.pname FROM orders, products WHERE orders.uid!='' AND
orders.pid=products.pid) or die(mysql_error());
while (list($opid, $ppid, $amount, $pname) = mysql_fetch_row($res)) {
$eval = '$temp['.$pname.'] = $temp['.$pname.'] + '.$amount.';';
eval($eval);
$i++;
}
arsort($temp);
return $temp;
}

It works fine for me, though I don't really need to select orders.pid and
products.pid since they aren't used. They are there when I was debugging but
*shrug*, I'm just too lazy to remove them right now!

Alex.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Re: eval()

2002-01-20 Thread Rasmus Lerdorf

   while (list($opid, $ppid, $amount, $pname) = mysql_fetch_row($res)) {
   $eval = '$temp['.$pname.'] = $temp['.$pname.'] + '.$amount.';';
   eval($eval);
   $i++;

Whoa...  Why not simply:

$temp[$pname] += $amount;

??

-Rasmus


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Re: eval()

2002-01-20 Thread Alex Dowgailenko

I tried that and strangely it didn't work and using eval() was really my
only solution :(
People told me to od $foo[$bar], $foo['$bar'], $foo[$bar], $foo[($bar)],
and the manual doesn't seem to mind $foo[$bar], but I dunno. It just wasn't
working, and I was angry and depressed that I wasn't getting paid enough for
what I was doing so I took the easy way out. It's the only time I ever used
eval() in PHP.

 -Original Message-
 From: Rasmus Lerdorf [mailto:[EMAIL PROTECTED]]
 Sent: January 20, 2002 11:22 PM
 To: Alex Dowgailenko
 Cc: [EMAIL PROTECTED]
 Subject: RE: [PHP] Re: eval()


  while (list($opid, $ppid, $amount, $pname) =
 mysql_fetch_row($res)) {
  $eval = '$temp['.$pname.'] = $temp['.$pname.']
 + '.$amount.';';
  eval($eval);
  $i++;

 Whoa...  Why not simply:

 $temp[$pname] += $amount;

 ??

 -Rasmus




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: eval on a form

2001-12-10 Thread Hugh Bothwell


Paul Roberts [EMAIL PROTECTED] wrote in message
000d01c18101$5dbb2220$01f8883e@laptop1">news:000d01c18101$5dbb2220$01f8883e@laptop1...
 Hi

 I'm trying to pre-fill a form ( the data is passed via sessions or from
 another script).

 i have some check boxes on the form that i would like checked if the
 variable is present.

 any ideas

I would write a checkbox-presenting function - pass it the name of
the variable the checkbox represents, it will see if the variable is set
(and if so, denote it CHECKED) and name the checkbox properly.
This should encapsulate stuff nicely and make your source easier to
follow; something like

function CondCheckbox($variablename) {
$str = INPUT TYPE='CHECKBOX' NAME='$variablename';

  if (isset($GLOBALS[$variablename]))
$str .=  CHECKED;

  return $str.;
}

(note: I have not actually run-tested this; it should be pretty close,
though)


Then your form will look something like

Ingredients:
FORM
?php
echo CondCheckbox(flour).Flourbr;
echo CondCheckbox(butter).Butterbr;
echo CondCheckbox(salt).Saltbr;
echo CondCheckbox(oatmeal).Oatmealbr;
?
input type='submit'
/FORM


Is this something like what you were after?  It would help
if you gave us a slightly more detailed idea of what sort of
data was involved.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]