Page 1 of 1

write to file

Posted: Tue Jul 06, 2004 9:23 pm
by ol4pr0
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 ?

Posted: Tue Jul 06, 2004 9:35 pm
by EricS
Create a string of the entire contents of the file, the print the string to a file.

Code: Select all

$string  = '______________________';
for ($i = 0; $i < 31; $i++) &#123;
     $string .= "\n\r";
&#125;
$string .= "some\twords\tin\tcolumns";

etc....

fprintf ($fileResource, $string);
This is a very simple example. But should work.

Posted: Tue Jul 06, 2004 9:40 pm
by ol4pr0
in other words i would have to create a new "for" and "string" for each line i need to print

Posted: Tue Jul 06, 2004 9:47 pm
by ol4pr0
that will not start at line 31, it will start on line 1.

However will it be easyer to have it just echo.s on screen ?

Posted: Tue Jul 06, 2004 10:33 pm
by EricS
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;

Posted: Tue Jul 06, 2004 10:51 pm
by ol4pr0
Thank you,

Posted: Tue Jul 06, 2004 10:55 pm
by EricS
An fprintf should yeild the exact same output in a file as what you see when you view the page source. If your still having problems, let me know and I'll see what I can do.

Posted: Tue Jul 06, 2004 11:17 pm
by ol4pr0
fprintf gives me a error
Parse error: parse error, unexpected T_VARIABLE oine 18
that is

Code: Select all

fprintf $string;
Had it now with <pre> however wondering about that fprintf now :)

Posted: Wed Jul 07, 2004 7:34 am
by feyd
[php_man]fprintf[/php_man]