Write an array to a txt file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Write an array to a txt file

Post 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!
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Re: Write an array to a txt file

Post 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.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Write an array to a txt file

Post by Kieran Huggins »

try serialize() instead of var_export()
Post Reply