redirect my own output

hello.

I wonder how can I redirect my own output to a single variable using php.

I want to change my stdout for another descriptor. My script runs in both web and shell environment so I need to change the scape characters ’
’ of the console to <br> for the web version using something like nl2br() function when I explicitly want to flush that variable and display its content.

I know that there is another way such use a custom function (that knows where is running the script) instead the natively implemented echo() function but with this, the code will look creepy and ugly.

Gracias :slight_smile:

castord said on 7/23/2008,

>I want to change my stdout for another descriptor. My script runs in
>both web and shell environment so I need to change the scape characters
>’
’ of the console to <br> for the web version using something like
>nl2br() function when I explicitly want to flush that variable and
>display its content.
>
>I know that there is another way such use a custom function (that knows
>where is running the script) instead the natively implemented echo()
>function but with this, the code will look creepy and ugly.

So basically a logger function, but you don’t want to log to a file, but
to stdout.


Jared Jennings - Data Technique, Inc.
Novell Support Forums Sysop
My Blog and Wiki with Tips, Tricks, and Tutorials
http://jaredjennings.org

That’s right.
I already use a solution that I didn’t like much, but seems to work. Instead echo() I wrote my own echo function which writes
on shell environment and <br> in web.
I still looking for the answer and the correct way to do that.

Strange that you use a PHP script for two purposes when one requires HTML and the other plain text.

However if you use a templating system like Smarty, you can generate different output formats depending on which template you use. E.g.

$template = new Smarty();
$template->assign('var', $somevar);
...
if ($toterminal)
  $template->display('terminal.tpl');
else
  $template->display('browser.tpl');

Strange that you use a PHP script for two purposes when one requires HTML and the other plain text.

Actually the script shouldn’t display any info but for debug purposes it was necessary. Sometimes I need to call it from a web browser and sometimes from a shell console.
This script is executed every five minutes, reads a db2 table, does some math operations and then stores the result in another table of another db2 database. The script is running in a IBM AS400 :(.
Is very hard to get use to this kind of OS when you have used Linux.