How to store the output as textfile

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hemashiki
    New Member
    • Aug 2006
    • 34

    How to store the output as textfile

    Hi
    i wanna help..While php script running in browsers,the output must stored as text file simultaneously.
    i dont know how to do..
    can anyone provide me a solution....
  • xwero
    New Member
    • Feb 2007
    • 99

    #2
    I think the simplest solution is to define a variable to catch the output to and if it's done write it to the textfile.

    [PHP]
    $textcontent = '';
    for($i=0;$i<10; $i++){
    // regular output
    echo $i.'<br>';
    // catching for file
    $textcontent .= $i.chr(10);
    }
    // php.net code ;)
    if (!$handle = fopen($filename , 'a')) {
    echo "Cannot open file ($filename)";
    exit;
    }
    if (fwrite($handle , $textcontent) === FALSE) {
    echo "Cannot write to file ($filename)";
    exit;
    }

    echo "Success, wrote ($textcontent) to file ($filename)";

    fclose($handle) ;
    [/PHP]

    it's not simultanious but it's very close.

    Comment

    • stephane
      New Member
      • Feb 2007
      • 35

      #3
      Originally posted by hemashiki
      Hi
      i wanna help..While php script running in browsers,the output must stored as text file simultaneously.
      i dont know how to do..
      can anyone provide me a solution....
      to store all output to variable you can use ob_ php fucntions
      var value, you can store at file at server or print to screen.

      Comment

      Working...