Topic: FWRITE - Why does "skip a line" influences subsequent writes? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=31458" title="Pages that link to Topic: FWRITE - Why does &amp;quot;skip a line&amp;quot; influences subsequent writes? (Page 1 of 1)" rel="nofollow" >Topic: FWRITE - Why does &quot;skip a line&quot; influences subsequent writes? <span class="small">(Page 1 of 1)</span>\

 
ruffy
Nervous Wreck (II) Inmate

From:
Insane since: Jun 2008

posted posted 11-06-2009 00:16

My code below writes the first line,
intermediate lines, and finally the
last line.

NOTE: I want to skip a line after writing the first,
and only the first, line.

But - putting the "\n" after the first write
causes ALL subsequent writes to ALSO skip
a line - something I do not want to happen,
even though those fwrites do NOT have the "\n"
in their syntax.

Why does the first write's skip action
influence the rest of the fwrites, and how,
then, do I get only the first skip executed
without causing further skips thereafter?

<?php
$file = fopen("./readArray.php","r");
$wfile = fopen("./writeArray.txt", "w");
fwrite($wfile, "var jsArray = [\n");
while(! feof($file))
{
$phpLine = fgets($file);
fwrite($wfile, $phpLine);
}
fclose($file);
fwrite($wfile, "]");
fclose($wfile);
?>

If I change the first fwrite statement to
fwrite($wfile, "var jsArray = [");
each write appears on their own line,
as I want it, except for the first line's
missing skip. How do I skip only
after the first fwrite?

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 11-06-2009 09:41

well, what you describe doesn't make sense,
but here's a stab.

But fgets will return a new line at the end of a line, perhaps that is your problem,
then the answer would be 'strip()'.

Or for some reason php opens one of these files with \r\n -> \n conversion and the otherone without...

"fwrite($wfile, "var jsArray = [\n");" shouldn't skip a line either, just simple introduce a line break.



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu