Sending output to a file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Xizor

    Sending output to a file

    Lets say I got something simple like:

    <?php

    echo "yo";
    echo "word";

    ?>

    I want all those echos to write to a file instead of printing to the screen
    without changing to a different function. Sort of like how in Unix you can
    do ./my_prog < file1 to output to a file. In this case I want it all to be
    done in code. For example, something like:

    <?php

    output_to_file_ instead_of_scre en();

    echo "yo";
    echo "word";

    output_to_scree n();

    ?>


  • Matthias Esken

    #2
    Re: Sending output to a file

    "Xizor" <nope@nope.co m> schrieb:
    [color=blue]
    > Lets say I got something simple like:
    >
    > <?php
    >
    > echo "yo";
    > echo "word";
    >
    > ?>
    >
    > I want all those echos to write to a file instead of printing to the screen
    > without changing to a different function.[/color]

    If I got it right, you don't want to use a switch in the function for
    echo() and fwrite(). In this case you could use output buffering. Your
    program can catch the output and write it to a file at the end of the
    script. Have a look at the output control functions at
    http://www.php.net/manual/en/ref.outcontrol.php.

    Matthias

    Comment

    • Xizor

      #3
      Re: Sending output to a file

      I did look at the manual. I looked under file functions and streams (cause C
      did this with streams). Didn't see it in either. Matthias pointed out the
      output control functions, which I missed. Thanks to him, not to you.


      "Ian.H [dS]" <ian@WINDOZEdig iserv.net> wrote in message
      news:n1jiivodo8 m134jradjqtbk9o 6tlvho8ge@4ax.c om...[color=blue]
      > -----BEGIN PGP SIGNED MESSAGE-----
      > Hash: SHA1
      >
      > Whilst lounging around on Thu, 31 Jul 2003 16:47:31 GMT, "Xizor"
      > <nope@nope.co m> amazingly managed to produce the following with their
      > Etch-A-Sketch:
      >[color=green]
      > > Lets say I got something simple like:
      > >
      > > <?php
      > >
      > > echo "yo";
      > > echo "word";
      > >
      > > ?>
      > >
      > > I want all those echos to write to a file instead of printing to
      > > the screen[/color]
      >
      >
      > So read the PHP Manual on http://www.php.net/. This is _VERY_ basic
      > stuff.. you did RTFM didn't you?
      >
      >
      >
      > Regards,
      >
      > Ian
      >
      > -----BEGIN PGP SIGNATURE-----
      > Version: PGP 8.0
      >
      > iQA/AwUBPylMcGfqtj2 51CDhEQLtXgCg5C sGhqRMunu/WIbUSjx0EQsm5gM AoKoy
      > GGbA8GzWJEzEtdK Z2gfFw0h8
      > =Xxjd
      > -----END PGP SIGNATURE-----
      >
      > --
      > Ian.H [Design & Development]
      > digiServ Network - Web solutions
      > www.digiserv.net | irc.digiserv.ne t | forum.digiserv. net
      > Programming, Web design, development & hosting.[/color]


      Comment

      • Xizor

        #4
        Re: Sending output to a file

        Thank you. Good stuff.



        "Matthias Esken" <muelleimer2003 @usenetverwaltu ng.org> wrote in message
        news:bgbqci.r0. 1@usenet.esken. de...[color=blue]
        > "Xizor" <nope@nope.co m> schrieb:
        >[color=green]
        > > Lets say I got something simple like:
        > >
        > > <?php
        > >
        > > echo "yo";
        > > echo "word";
        > >
        > > ?>
        > >
        > > I want all those echos to write to a file instead of printing to the[/color][/color]
        screen[color=blue][color=green]
        > > without changing to a different function.[/color]
        >
        > If I got it right, you don't want to use a switch in the function for
        > echo() and fwrite(). In this case you could use output buffering. Your
        > program can catch the output and write it to a file at the end of the
        > script. Have a look at the output control functions at
        > http://www.php.net/manual/en/ref.outcontrol.php.
        >
        > Matthias[/color]


        Comment

        • Matthias Esken

          #5
          Re: Sending output to a file

          "Xizor" <nope@nope.co m> schrieb:
          [color=blue]
          > I did look at the manual. I looked under file functions and streams (cause C
          > did this with streams). Didn't see it in either. Matthias pointed out the
          > output control functions, which I missed. Thanks to him, not to you.[/color]

          Well, I think Ian got the question wrong.

          Hope this output control works for you.

          Matthias

          Comment

          Working...