Jump to content

fwrite array, is this possible?


JREAM

Recommended Posts

I cant figure wyh this won't write? or read?

I want to be able to write it line for line, i know how you read it line for line

Is this possible?

 

<?php

// set file to write
$file = 'dump.txt';
// open file
$fh = fopen($file, 'w+') or die('Could not open file!');
// read file into array

$data = file($fh) or die('Could not read file!');

foreach ($data as $line) {
     echo $line;
// write to file
fwrite($fh, "Look, Ma, I wrote a file! ");
fwrite($fh, "123 ");
fwrite($fh, "54 ");	
// close file

}

fclose($fh);
?>

Link to comment
https://forums.phpfreaks.com/topic/120943-fwrite-array-is-this-possible/
Share on other sites

The file() function takes a string file name. Passing it a file-handle from an fopen() function is meaningless.

 

file

(PHP 4, PHP 5)

 

file — Reads entire file into an array

 

Description

array file ( string $filename [, int $flags [, resource $context]] )

 

Reads an entire file into an array.

 

Note: You can use file_get_contents() to return the contents of a file as a string.

 

Parameters

 

filename

Path to the file.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.