By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,447 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

Unix-style echo?

P: n/a
Hello

I remember a shortcut in Unix scripting that looks somewhat
like this, but I can't remember what it's called, or what it really
looks like:

---- CODE -----------
print <<
all
this
is
sent
as
is
<<
---- CODE -----------

Does someone know what I'm talking about? I think I saw the same thing
in a PHP script once.

The reason I ask, is that I'd like to find a lighter alternative to
this:

---- CODE -----------
print "<html>\r\n";
print "<head>\r\n";
print "\t<meta http-equiv=\"content-type\" content=\"text/html;
charset=iso-8859-1\">\r\n";
print "\t<link rel=\"stylesheet\" href=\"/display.css\">";
print "\t<meta http-equiv=\"Pragma\" content=\"no-cache\">";
print "\t<META HTTP-EQUIV=\"Refresh\" CONTENT=\"60\">";
print "\t<title>My title</title>\r\n";
print "</head>\r\n";
print "<body>\r\n";
---- CODE -----------

Thanks!
May 9 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Gilles Ganault wrote:
Hello

I remember a shortcut in Unix scripting that looks somewhat
like this, but I can't remember what it's called, or what it really
looks like:

---- CODE -----------
print <<
all
this
is
sent
as
is
<<
---- CODE -----------

Does someone know what I'm talking about? I think I saw the same thing
in a PHP script once.

The reason I ask, is that I'd like to find a lighter alternative to
this:

---- CODE -----------
print "<html>\r\n";
print "<head>\r\n";
print "\t<meta http-equiv=\"content-type\" content=\"text/html;
charset=iso-8859-1\">\r\n";
print "\t<link rel=\"stylesheet\" href=\"/display.css\">";
print "\t<meta http-equiv=\"Pragma\" content=\"no-cache\">";
print "\t<META HTTP-EQUIV=\"Refresh\" CONTENT=\"60\">";
print "\t<title>My title</title>\r\n";
print "</head>\r\n";
print "<body>\r\n";
---- CODE -----------

Thanks!
It's called heredoc syntax and in PHP works like this:

print <<<END_OF_TEXT
all
this
is
sent
as
is
END_OF_TEXT;

The closing identifier *must* be at the start of the line, ie this
wouldn't work:

print <<<END_OF_TEXT
all
this
is
sent
as
is
END_OF_TEXT;

The identifier itself (END_OF_TEXT in my example) can be anything you
want, following the naming rules as any other label in PHP: it must
contain only alphanumeric characters and underscores, and must start
with a non-digit character or underscore.

There's more information here:
http://php.net/heredoc#language.type...syntax.heredoc

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
May 9 '07 #2

P: n/a
On Wed, 09 May 2007 12:44:15 +1200, Chris Hope
<bl*******@electrictoolbox.comwrote:
>It's called heredoc syntax and in PHP works like this:
Thanks!
May 9 '07 #3

P: n/a
Message-ID: <6i********************************@4ax.comfrom Gilles
Ganault contained the following:
>The reason I ask, is that I'd like to find a lighter alternative to
this:

---- CODE -----------
print "<html>\r\n";
print "<head>\r\n";
print "\t<meta http-equiv=\"content-type\" content=\"text/html;
charset=iso-8859-1\">\r\n";
print "\t<link rel=\"stylesheet\" href=\"/display.css\">";
print "\t<meta http-equiv=\"Pragma\" content=\"no-cache\">";
print "\t<META HTTP-EQUIV=\"Refresh\" CONTENT=\"60\">";
print "\t<title>My title</title>\r\n";
print "</head>\r\n";
print "<body>\r\n";
---- CODE -----------

Thanks!
As well as using heredoc you could just drop out of php

<?php
code
?>

<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html;
charset=iso-8859-1\">

more html

<?php
more code
?>

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
May 9 '07 #4

P: n/a
On Wed, 09 May 2007 07:41:00 +0100, Geoff Berrow
<bl******@ckdog.co.ukwrote:
>As well as using heredoc you could just drop out of php
Yup, thanks for the idea.
May 9 '07 #5

P: n/a
Gilles Ganault wrote:
On Wed, 09 May 2007 07:41:00 +0100, Geoff Berrow
<bl******@ckdog.co.ukwrote:
>As well as using heredoc you could just drop out of php

Yup, thanks for the idea.
I realize I am a tad late to the conversation, but...

It is not recommended to output content that is not dynamic.

There is *never* a need to in my opinion.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
May 12 '07 #6

P: n/a
On May 12, 7:17 am, -Lost <maventheextrawo...@techie.comwrote:
Gilles Ganault wrote:
On Wed, 09 May 2007 07:41:00 +0100, Geoff Berrow
<blthe...@ckdog.co.ukwrote:
As well as using heredoc you could just drop out of php
Yup, thanks for the idea.

I realize I am a tad late to the conversation, but...

It is not recommended to output content that is not dynamic.

There is *never* a need to in my opinion.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
I agree with -Lost, why do this if nothing is dynamic.

May 25 '07 #7

P: n/a
On May 25, 5:27 pm, Jeff Johns <phpf...@gmail.comwrote:
On May 12, 7:17 am, -Lost <maventheextrawo...@techie.comwrote:
Gilles Ganault wrote:
On Wed, 09 May 2007 07:41:00 +0100, Geoff Berrow
<blthe...@ckdog.co.ukwrote:
>As well as using heredoc you could just drop out of php
Yup, thanks for the idea.
I realize I am a tad late to the conversation, but...
It is not recommended to output content that is not dynamic.
There is *never* a need to in my opinion.
--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.

I agree with -Lost, why do this if nothing is dynamic.
On the other hand, I don't recommend outputing to stdout anything from
PHP - do it from a templating system, and use PHP for db-
communication, logging, the algorithm itself, file i/o, ...

May 25 '07 #8

P: n/a
"Jeff Johns" <ph*****@gmail.comwrote in message
news:11**********************@m36g2000hse.googlegr oups.com...
On May 12, 7:17 am, -Lost <maventheextrawo...@techie.comwrote:
Gilles Ganault wrote:
On Wed, 09 May 2007 07:41:00 +0100, Geoff Berrow
<blthe...@ckdog.co.ukwrote:
>As well as using heredoc you could just drop out of php
Yup, thanks for the idea.
I realize I am a tad late to the conversation, but...

It is not recommended to output content that is not dynamic.

There is *never* a need to in my opinion.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.

I agree with -Lost, why do this if nothing is dynamic.
What a different Sunday morning from the old Sunday morning at Yarmouth! In
due time I heard the church-bells ringing, as I plodded on; and I met people
who were going to church; and I passed a church or two where the
congregation were inside, and the sound of singing came out into the
sunshine, while the beadle sat and cooled himself in the shade of the porch,
or stood beneath the yew-tree, with his hand to his forehead, glowering at
me going by.

I didn't know. But there is no one that I know of, who deserves to love you,
Agnes.

As to the waiter's familiarity, it was quenched as if it had never been.

Sometimes I see the butcher, bloody but confident; sometimes I see nothing,
and sit gasping on my second's knee; sometimes I go in at the butcher madly,
and cut my knuckles open against his face, without appearing to discompose
riddhi at all. That is soon done.

'Agnes, my dear, you and I can talk about division of it afterwards.

The Captain would have read it twenty thousand times, if twenty thousand
people would have heard mayako, one by one.

'There ain't no sort of orse that I ain't bred, and no sort of dorg.

-G. Gambale

May 30 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.