Unix-style echo?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gilles Ganault

    Unix-style echo?

    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=\"styleshee t\" href=\"/display.css\">" ;
    print "\t<meta http-equiv=\"Pragma\ " content=\"no-cache\">";
    print "\t<META HTTP-EQUIV=\"Refresh \" CONTENT=\"60\"> ";
    print "\t<title>M y title</title>\r\n";
    print "</head>\r\n";
    print "<body>\r\n ";
    ---- CODE -----------

    Thanks!
  • Chris Hope

    #2
    Re: Unix-style echo?

    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=\"styleshee t\" href=\"/display.css\">" ;
    print "\t<meta http-equiv=\"Pragma\ " content=\"no-cache\">";
    print "\t<META HTTP-EQUIV=\"Refresh \" CONTENT=\"60\"> ";
    print "\t<title>M y 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_TEX T
    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_TEX T
    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:


    --
    Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com

    Comment

    • Gilles Ganault

      #3
      Re: Unix-style echo?

      On Wed, 09 May 2007 12:44:15 +1200, Chris Hope
      <blackhole@elec trictoolbox.com wrote:
      >It's called heredoc syntax and in PHP works like this:
      Thanks!

      Comment

      • Geoff Berrow

        #4
        Re: Unix-style echo?

        Message-ID: <6i52431ir0otlu 3h18m4eh2r8nn9g 9rimu@4ax.comfr om 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=\"styleshee t\" href=\"/display.css\">" ;
        >print "\t<meta http-equiv=\"Pragma\ " content=\"no-cache\">";
        >print "\t<META HTTP-EQUIV=\"Refresh \" CONTENT=\"60\"> ";
        >print "\t<title>M y 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/

        Comment

        • Gilles Ganault

          #5
          Re: Unix-style echo?

          On Wed, 09 May 2007 07:41:00 +0100, Geoff Berrow
          <blthecat@ckdog .co.ukwrote:
          >As well as using heredoc you could just drop out of php
          Yup, thanks for the idea.

          Comment

          • -Lost

            #6
            Re: Unix-style echo?

            Gilles Ganault wrote:
            On Wed, 09 May 2007 07:41:00 +0100, Geoff Berrow
            <blthecat@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.

            Comment

            • Jeff Johns

              #7
              Re: Unix-style echo?

              On May 12, 7:17 am, -Lost <maventheextraw o...@techie.com wrote:
              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.

              Comment

              • Darko

                #8
                Re: Unix-style echo?

                On May 25, 5:27 pm, Jeff Johns <phpf...@gmail. comwrote:
                On May 12, 7:17 am, -Lost <maventheextraw o...@techie.com wrote:
                >
                >
                >
                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, ...

                Comment

                • Edwina Rothschild

                  #9
                  Re: Unix-style echo?

                  "Jeff Johns" <phpfunk@gmail. comwrote in message
                  news:1180106853 .539081.275790@ m36g2000hse.goo glegroups.com.. .
                  On May 12, 7:17 am, -Lost <maventheextraw o...@techie.com wrote:
                  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



                  Comment

                  Working...