write to file
Moderator: General Moderators
write to file
writing to a file is not my problem however the following is.
i need to write to a file that needs to be printed out. however the file needs to written like this..
_____________________________________________
nothing
line 23
some words in columns
_________ _________ ____________ ___________
$row['field'] $row['field'] ect...
line 30
__________ some other text again.
how can i accomplish this ?
i need to write to a file that needs to be printed out. however the file needs to written like this..
_____________________________________________
nothing
line 23
some words in columns
_________ _________ ____________ ___________
$row['field'] $row['field'] ect...
line 30
__________ some other text again.
how can i accomplish this ?
Create a string of the entire contents of the file, the print the string to a file.
This is a very simple example. But should work.
Code: Select all
$string = '______________________';
for ($i = 0; $i < 31; $i++) {
$string .= "\n\r";
}
$string .= "some\twords\tin\tcolumns";
etc....
fprintf ($fileResource, $string);Okay run this script. Now, do not worry about what it looks like when display right from the browser, look at the page source. You will see all the blank lines are there.
Code: Select all
// start the string with 22 blank lines
$newline = "\r\n";
for($i = 0; $i < 22; $i++) {
$string .= $newline;
}
// start the text on line 23
$string .= "_____\t_____\t_____\t_____".$newline;
$string .= "row1 \trow2 \trow3 \trow4";
// add 5 more blank lines
for($i = 0; $i < 5; $i++) {
$string .= $newline;
}
// start the text 30
$string .= "_____\t_____\t_____\t_____".$newline;
$string .= "row1 \trow2 \trow3 \trow4";
print $string;fprintf gives me a error
Had it now with <pre> however wondering about that fprintf now 
that isParse error: parse error, unexpected T_VARIABLE oine 18
Code: Select all
fprintf $string;