[PHP] eval() question

2004-04-21 Thread OrangeHairedBoy
I would like to use eval() to evaluate another PHP file and store the output
of that file in a string.

So, let's say, for example, that I have a file called colors.php which
contains this:

pColors: ? echo Red, Yellow, Green, Blue; ?/p

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



RE: [PHP] eval() question

2004-04-21 Thread Michael Sims
OrangeHairedBoy wrote:
 I would like to use eval() to evaluate another PHP file and store the
 output of that file in a string.

You could use output buffering to do this a bit more easily, I think:

ob_start();
include('colors.php');
$colors = ob_get_contents();
ob_end_clean();

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



Re: [PHP] eval() question

2004-04-21 Thread OrangeHairedBoy
While that is an awesome idea, I don't think it will work for me.

There's two reasons why. First, colors.php is actually stored in a MySQL
server.

Second, before the PHP code inside colors.php I want to be able to replace
data inside that file. For example:

$file = str_replace( Green , Orange , $file );

Lewis


Michael Sims [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 OrangeHairedBoy wrote:
  I would like to use eval() to evaluate another PHP file and store the
  output of that file in a string.

 You could use output buffering to do this a bit more easily, I think:

 ob_start();
 include('colors.php');
 $colors = ob_get_contents();
 ob_end_clean();

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



Re: [PHP] eval() question

2004-04-21 Thread Marek Kilimajer
OrangeHairedBoy wrote:
I would like to use eval() to evaluate another PHP file and store the output
of that file in a string.
So, let's say, for example, that I have a file called colors.php which
contains this:
pColors: ? echo Red, Yellow, Green, Blue; ?/p

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?

eval starts in php mode by default, change the file content to

?pColors: ? echo Red, Yellow, Green, Blue; ?/p?

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


Re: [PHP] eval() question

2004-04-21 Thread OrangeHairedBoy
Marek,

OK...that worked...kinda, but it doesn't pass the output to $colors. It
echos it. I need the output to be passed to $colors.

Lewis

Marek Kilimajer [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 OrangeHairedBoy wrote:
  I would like to use eval() to evaluate another PHP file and store the
output
  of that file in a string.
 
  So, let's say, for example, that I have a file called colors.php which
  contains this:
 
  pColors: ? echo Red, Yellow, Green, Blue; ?/p
 
  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?
 

 eval starts in php mode by default, change the file content to

 ?pColors: ? echo Red, Yellow, Green, Blue; ?/p?

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



RE: [PHP] eval() question

2004-04-21 Thread Michael Sims
 OrangeHairedBoy wrote:
 I would like to use eval() to evaluate another PHP file and store
 the output of that file in a string.

 You could use output buffering to do this a bit more easily, I think:

 ob_start();
 include('colors.php');
 $colors = ob_get_contents();
 ob_end_clean();

 While that is an awesome idea, I don't think it will work for me.

 There's two reasons why. First, colors.php is actually stored in a
 MySQL server.

 Second, before the PHP code inside colors.php I want to be able to
 replace data inside that file. For example:

 $file = str_replace( Green , Orange , $file );

Ok, then a slight adjustment should work:

$file = file_get_contents( colors.php );
$file = str_replace( Green , Orange , $file );
ob_start();
eval( $file );
$colors = ob_get_contents();
ob_end_clean();

I've never done that personally, but the documentation for eval() states:

In PHP 4, eval() returns NULL unless return is called in the evaluated code,
in which case the value passed to return is returned.

And then:

Tip: As with anything that outputs its result directly to the browser, you
can use the output-control functions to capture the output of this function,
and save it in a string (for example).

HTH...

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



Re: [PHP] eval() question

2004-04-21 Thread OrangeHairedBoy
Thanks Michael  Marek! It worked! :)


Michael Sims [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
  OrangeHairedBoy wrote:
  I would like to use eval() to evaluate another PHP file and store
  the output of that file in a string.
 
  You could use output buffering to do this a bit more easily, I think:
 
  ob_start();
  include('colors.php');
  $colors = ob_get_contents();
  ob_end_clean();
 
  While that is an awesome idea, I don't think it will work for me.
 
  There's two reasons why. First, colors.php is actually stored in a
  MySQL server.
 
  Second, before the PHP code inside colors.php I want to be able to
  replace data inside that file. For example:
 
  $file = str_replace( Green , Orange , $file );

 Ok, then a slight adjustment should work:

 $file = file_get_contents( colors.php );
 $file = str_replace( Green , Orange , $file );
 ob_start();
 eval( $file );
 $colors = ob_get_contents();
 ob_end_clean();

 I've never done that personally, but the documentation for eval() states:

 In PHP 4, eval() returns NULL unless return is called in the evaluated
code,
 in which case the value passed to return is returned.

 And then:

 Tip: As with anything that outputs its result directly to the browser, you
 can use the output-control functions to capture the output of this
function,
 and save it in a string (for example).

 HTH...

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