By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,253 Members | 1,693 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,253 IT Pros & Developers. It's quick & easy.

Unable to write an array to a file

P: 1
hi All,

I am extracting data from a website using a automation tool. I am getting the data in the form of an array, which I want to write it in a text file. Please have a look at the below piece of code which is not working. it creates a file but just write a word 'Array' into it instead of the data.

$rec = split("\[EXTRACT\]", $e);

echo "$rec";
//inserting the extracted data in to text file
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $rec);
fclose($fh);

Any quick help is really appreciated.
Jul 25 '07 #1
Share this Question
Share on Google+
3 Replies


kovik
Expert 100+
P: 1,044
And what seems to be the problem?
Jul 26 '07 #2

pbmods
Expert 5K+
P: 5,821
Heya, tejas900. Welcome to TSDN!

When you try to print() an array, it will output as 'Array'. Not too helpful. What you want is var_export() instead.
Jul 26 '07 #3

kovik
Expert 100+
P: 1,044
A more common approach is print_r().

You'd likely want to actually traverse your arrays and add each index into the file.
[php]foreach($rec as $data)
{
echo $data;
}[/php]

That should give you an idea of how it's done.
Jul 26 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.