I'm now looking at this example:
<?php // testfile.php
$fh = fopen("testfile.txt", 'w') or die("Failed to create file");
$text = <<<_END
Line 1
Line 2
Line 3
_END;
fwrite($fh, $text) or die("Could not write to file");
fclose($fh);
echo "File 'testfile.txt' written successfully";
?>
Now I'm expecting, and the O'Reilly book is suggesting that the file
should have 3 lines of text, since that is what the heredoc has. If I
open the file with Notepad, it is just one line as follows:
Line 1Line 2Line 3
However, when I copied/pasted the text from the Notepad file to here,
it indeed gave 3 lines as follows:
Line 1
Line 2
Line 3
So what phenomena are at work here? I'm assuming that the newline
characters inserted by PHP might not be the same newline characters
recognized by Notepad? I think I might have once read something along
those lines?
Thanks, as always.
When I inserted line breaks in the notepad file and got the lines to
appear one string per line, I copied it into my editor (Netbeans ide)
and it appeared as follows:
<?php // testfile.php
$fh = fopen("testfile.txt", 'w') or die("Failed to create file");
$text = <<<_END
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
_END;
fwrite($fh, $text) or die("Could not write to file");
fclose($fh);
echo "File 'testfile.txt' written successfully";
?>
So it seems that I'm getting an extra line of whitespace when the
linened (or carriage return?) is inserted into notepad.
However, running it as a PHP program, again seems to eat al
lwhitespace in the file, giving me a line that appears in Notepad as a
single line.
Blegh.
>as a quick aside. Is there a better place to ask php questions, since
>this ng is so overrun by spammers?
What spammers? There's some spam once a week or so, but I wouldn't call
that overrun.
>I'm now looking at this example:
><?php // testfile.php
>$fh = fopen("testfile.txt", 'w') or die("Failed to create file");
>$text = <<<_END
>Line 1
>Line 2
>Line 3
>
>_END;
>fwrite($fh, $text) or die("Could not write to file");
>fclose($fh);
>echo "File 'testfile.txt' written successfully";
>?>
>
>Now I'm expecting, and the O'Reilly book is suggesting that the file
>should have 3 lines of text, since that is what the heredoc has.
I would expect four lines: three with text, one empty.
>If I
>open the file with Notepad, it is just one line as follows:
>
>Line 1Line 2Line 3
>
>However, when I copied/pasted the text from the Notepad file to here,
>it indeed gave 3 lines as follows:
>
>Line 1
>Line 2
>Line 3
>
>
>So what phenomena are at work here?
Probably just Notepad's incapability to display non-Windows line breaks.
>I'm assuming that the newline
>characters inserted by PHP might not be the same newline characters
>recognized by Notepad?
Seems so. Have a look at the parameters for fopen(), especially the 'b'
parameter to force binary mode. It might also make sense to drop Notepad
and use a better editor instead. Especially for programming you need at
least syntax highlighting anyway.
What I do here to avoid such problems is that I always use *nix-like
line endings ("\n"), even if I'm developing on a Windows machine. My IDE
is configured to use these line endings in all scripts. And whenever I
have to deal with text files, I always treat them in a binary way, i.e.
I don't let any kind of software change the line endings. Neither in my
scripts nor during an FTP upload etc. My files are always treated as
they are.
Micha
> .oO(MikeB)
>
>>as a quick aside. Is there a better place to ask php questions, since
>>this ng is so overrun by spammers?
>
> What spammers? There's some spam once a week or so, but I wouldn't call
> that overrun.
It's far, FAR worse if you're using Google Groups, rather than a real
usenet provider.
>>So what phenomena are at work here?
>
> Probably just Notepad's incapability to display non-Windows line breaks.
Exactly.
> It might also make sense to drop Notepad
> and use a better editor instead. Especially for programming you need at
> least syntax highlighting anyway.
Notepad++ is a good choice if you're on Windows:
<http://notepad-plus-plus.org/>
sherm--
--
Sherm Pendley
<http://camelbones.sourceforge.net>
Cocoa Developer
>Michael Fesser <net...@gmx.de> writes:
>
>> .oO(MikeB)
>>
>>>as a quick aside. Is there a better place to ask php questions, since
>>>this ng is so overrun by spammers?
>>
>> What spammers? There's some spam once a week or so, but I wouldn't call
>> that overrun.
>
>It's far, FAR worse if you're using Google Groups, rather than a real
>usenet provider.
OK, thanks. Didn't notice he's using GG. ;-)
But right, then it might be a problem. GG sucks anyway and many people
killfile anything coming from there.
@MikeB: You should get a newsreader and use a real Usenet server, not
such an ugly web-based fake.
Micha
My ISP doesn't carry newsgroup servers. At the risk of sounding petty,
I don't really want to use a for-pay NNTP server. If it really
matters to y'all I guess I can use a newsreader and subscribe to the
PHP newsgroup that way, but using gg I have all the newsgroups I use
in one place. Or I can switch to the listservers.
And if people feel so strongly about GG that they killfile me, then
there's not much I can do. I think I've read once why they do it, but
I can't even remember anymore.
> My ISP doesn't carry newsgroup servers.
Neither does mine.
> At the risk of sounding petty,
> I don't really want to use a for-pay NNTP server.
Who said anything about paying for it? :-)
I'm happy with: <http://x-privat.org>. They carry all the groups I
care about.
> If it really matters to y'all
You're the one who complained about spam, not me...
You just need a better server. Drop Google Groups, find a real
newsreader (Opera or Thunderbird may do) and open an account in a decent
Usenet service, such as http://www.eternal-september.org/
See Michael Fesser's reply and, if you're really curious about the
subject, have a look at http://en.wikipedia.org/wiki/Newline
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
>MikeB <mpb...@gmail.com> writes:
>
>> At the risk of sounding petty,
>> I don't really want to use a for-pay NNTP server.
>
>Who said anything about paying for it? :-)
>
>I'm happy with: <http://x-privat.org>. They carry all the groups I
>care about.
And even a commercial news service doesn't have to be expensive. I pay
10 EUR/year for http://news.individual.net, which is almost nothing. The
server is very reliable, properly maintained, filters spam etc.
Micha
> Micha
>
>My ISP doesn't carry newsgroup servers. At the risk of sounding petty,
>I don't really want to use a for-pay NNTP server. If it really
>matters to y'all I guess I can use a newsreader and subscribe to the
>PHP newsgroup that way, but using gg I have all the newsgroups I use
>in one place. Or I can switch to the listservers.
Their are free NNTP news servers.
I use http://aioe.org
--
Kev Wells http://riscos.kevsoft.co.uk/
http://kevsoft.co.uk/ http://kevsoft.co.uk/AleQuest/
ICQ 238580561
Work the curse of the drinking class.
And if you are restricted to a web Usenet portal, like I am, a good
solution is a GreaseMonkey script called "Google Groups Killfile"
> Notepad++ is a good choice if you're on Windows:
>
> <http://notepad-plus-plus.org/>
Gedit has been ported to Windows, too. Both allow Zen Coding IIRC.
> Funny enough, if I open the file in WordPad, I see all the expected
> line breaks. So it must be "something" with Notepad.
My guess is the text file is most likely using Unix style end of line
markers and Notepad is expecting Windows end of line markers.
FWIW the Zeus editor can handle both Unix and Windows styles of end
of line marking:
Jussi Jumppanen
Author: Zeus for Windows IDE
Zen coding. What an interesting idea. Thanks for mentioning that and
getting me interested.
> Who said anything about paying for it? :-)
>
> I'm happy with: <http://x-privat.org>. They carry all the groups I
> care about.
>
Hmm.. I might be repeating myself.
Sherm, if you read this.
I've got a newsreader installed and working on another limited
newsgroup. If you would be so kind to send me an invitation for
http://x-privat.org/ I'd appreciate it.
Thanks,
Mike