Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Another heredoc question

0 views
Skip to first unread message

MikeB

unread,
Sep 2, 2010, 2:26:51 PM9/2/10
to
as a quick aside. Is there a better place to ask php questions, since
this ng is so overrun by spammers?

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.

MikeB

unread,
Sep 2, 2010, 2:33:11 PM9/2/10
to
Sort of an update:

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.

MikeB

unread,
Sep 2, 2010, 2:35:55 PM9/2/10
to
Funny enough, if I open the file in WordPad, I see all the expected
line breaks. So it must be "something" with Notepad.

Blegh.

Michael Fesser

unread,
Sep 2, 2010, 2:41:08 PM9/2/10
to
.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.

>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

Sherm Pendley

unread,
Sep 2, 2010, 2:49:04 PM9/2/10
to
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.

>>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

unread,
Sep 2, 2010, 2:55:37 PM9/2/10
to
.oO(Sherm Pendley)

>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

MikeB

unread,
Sep 2, 2010, 6:54:27 PM9/2/10
to
On Sep 2, 1:55 pm, Michael Fesser <neti...@gmx.de> wrote:
> .oO(Sherm Pendley)

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.

Sherm Pendley

unread,
Sep 2, 2010, 7:49:32 PM9/2/10
to
MikeB <mpb...@gmail.com> writes:

> 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...

"Álvaro G. Vicario"

unread,
Sep 3, 2010, 2:17:32 AM9/3/10
to
El 02/09/2010 20:26, MikeB escribió/wrote:
> as a quick aside. Is there a better place to ask php questions, since
> this ng is so overrun by spammers?

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
--

Michael Fesser

unread,
Sep 3, 2010, 4:38:11 AM9/3/10
to
.oO(Sherm Pendley)

>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

Kevin Wells

unread,
Sep 3, 2010, 9:17:00 AM9/3/10
to
In message <0f0b2bc8-da00-4272...@f25g2000yqc.googlegroups.com>
MikeB <mpb...@gmail.com> wrote:

> 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.

matt

unread,
Sep 3, 2010, 10:55:19 AM9/3/10
to
On Sep 2, 2:49 pm, Sherm Pendley <sherm.pend...@gmail.com> wrote:

> Michael Fesser <neti...@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.

And if you are restricted to a web Usenet portal, like I am, a good
solution is a GreaseMonkey script called "Google Groups Killfile"

Derek Turner

unread,
Sep 5, 2010, 3:32:39 AM9/5/10
to
On Thu, 02 Sep 2010 14:49:04 -0400, Sherm Pendley wrote:

> 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.

JussiJ

unread,
Sep 8, 2010, 9:27:25 PM9/8/10
to
On Sep 3, 4:35 am, MikeB <mpbr...@gmail.com> wrote:

> 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:

http://www.zeusedit.com/

Jussi Jumppanen
Author: Zeus for Windows IDE

MikeB

unread,
Sep 9, 2010, 5:47:08 PM9/9/10
to

Zen coding. What an interesting idea. Thanks for mentioning that and
getting me interested.

MikeB

unread,
Sep 12, 2010, 2:17:26 PM9/12/10
to
On Sep 2, 6:49 pm, Sherm Pendley <sherm.pend...@gmail.com> wrote:

> 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

0 new messages