Inserting a blank line in file write

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
vivsriaus
Forum Newbie
Posts: 7
Joined: Tue Jan 10, 2006 11:03 am

Inserting a blank line in file write

Post by vivsriaus »

hawleyjr | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Here is a piece of my code

Code: Select all

while ($data = fgetcsv ($fp, 1000)) {
	$num = count ($data);
	for ($c=0; $c < $num; $c++) {
		$mult[$row][$c] = $data[$c].",";
		//$mult[$row][$c] = $data[$c]
		fwrite($fp1, $mult[$row][$c]);
		}
	$row ++;
	}
I need to insert a blank line after each iteration of 'c' loop. ie., when the 1st iteration of the c loop exits, I need to insert a blank line and continue doin the same.

Any inputs?


hawleyjr | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Inserting a blank line in file write

Post by Christopher »

Something like:

Code: Select all

while ($data = fgetcsv ($fp, 1000)) {
	$num = count ($data);
	for ($c=0; $c < $num; $c++) {
		$mult[$row][$c] = $data[$c].",";
		//$mult[$row][$c] = $data[$c]
		fwrite($fp1, $mult[$row][$c]);
		}
	fwrite($fp1, "\n\n");
	$row ++;
	}
(#10850)
vivsriaus
Forum Newbie
Posts: 7
Joined: Tue Jan 10, 2006 11:03 am

Post by vivsriaus »

yup!
I realize tht this is a stupid qstn which i posted in a hurry! I mustve lost my mind then! :))
Anyway, thnx
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

haha, welcome to the forums! :D

how i do it is, i just enter after the script

example

$content is being written to the page

Code: Select all

$content = "<html><title>My Site</title><font color=red size=3>This is my data!</font></html>
";
probably the wrong thing to do, what do i know :D
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

vivsriaus wrote:yup!
I realize tht this is a stupid qstn which i posted in a hurry! I mustve lost my mind then! :))
Anyway, thnx
Someone here said that there are no stupid questions -- only stupid answers. Well ... I agree about the questions. As for answers, as they are free, what is it about looking a gift horse in the mouth. :D
(#10850)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

arborint wrote:
vivsriaus wrote:yup!
I realize tht this is a stupid qstn which i posted in a hurry! I mustve lost my mind then! :))
Anyway, thnx
Someone here said that there are no stupid questions -- only stupid answers. Well ... I agree about the questions. As for answers, as they are free, what is it about looking a gift horse in the mouth. :D
No stupid answers here.. unless its spam. :evil:
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

nickman013 wrote:haha, welcome to the forums! :D

how i do it is, i just enter after the script

example

$content is being written to the page

Code: Select all

$content = "<html><title>My Site</title><font color=red size=3>This is my data!</font></html>
";
probably the wrong thing to do, what do i know :D
It works, but what happens when you want 3 line breaks? There goes the code readability ;)

Code: Select all

$content = "<html><title>My Site</title><font color=red size=3>This is my data!</font></html>\n\n\n";
That's the equivelant of 3 "enters".
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

d3ad1ysp0rk wrote:That's the equivelant of 3 "enters".
Yep. But would this be better:

Code: Select all

$content = "<html>\n<title>My Site</title>\n<font color=red size=3>This is my data!</font>\n</html>";
(#10850)
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

yeah, use the right way so nothing will get messed up
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

arborint wrote:
d3ad1ysp0rk wrote:That's the equivelant of 3 "enters".
Yep. But would this be better:

Code: Select all

$content = "<html>\n<title>My Site</title>\n<font color=red size=3>This is my data!</font>\n</html>";
Of course it would be better, I was just introducing the use of \n, not a production-ready product. ;)
Post Reply