Topic: FWRITE - Why does "skip a line" influences subsequent writes? (Page 1 of 1) Pages that link to <a href="" 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>\

Nervous Wreck (II) Inmate

Insane since: Jun 2008

IP logged posted posted 11-06-2009 00:16 Edit Quote

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?

$file = fopen("./readArray.php","r");
$wfile = fopen("./writeArray.txt", "w");
fwrite($wfile, "var jsArray = [\n");
while(! feof($file))
$phpLine = fgets($file);
fwrite($wfile, $phpLine);
fwrite($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

IP logged posted posted 11-06-2009 09:41 Edit Quote

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: Remember Me On This Computer
Your Text:
Options: Show Signature
Enable Slimies
Enable Linkwords

« BackwardsOnwards »

Show Forum Drop Down Menu