write to 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
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

write to file

Post 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 ?
EricS
Forum Contributor
Posts: 183
Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga

Post 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.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

in other words i would have to create a new "for" and "string" for each line i need to print
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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 ?
EricS
Forum Contributor
Posts: 183
Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga

Post 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;
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Thank you,
EricS
Forum Contributor
Posts: 183
Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga

Post 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.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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 :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[php_man]fprintf[/php_man]
Post Reply