Page 1 of 1

Write an array to a txt file

Posted: Tue Feb 05, 2008 11:40 am
by GeXus
Does anyone know how I can write an array to a text file? Basically I want to full post array to a text file. Thanks!

Re: Write an array to a txt file

Posted: Tue Feb 05, 2008 11:48 am
by GeXus

Code: Select all

 
    $myFile = "post.txt";
        $fh = fopen($myFile, 'w') or die("can't open file");
        $stringData = var_export($_POST); 
        fwrite($fh, $stringData);
    fclose($fh);
    echo $stringData;
 
I've tried this, but it doesn't work. No errors or anything, it just doesn't write to a file. If I change the stringData value to something like 'test', then it writes fine.

Re: Write an array to a txt file

Posted: Tue Feb 05, 2008 11:52 am
by Kieran Huggins
try serialize() instead of var_export()