echo <<<tag ... tag;

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael G

    echo <<<tag ... tag;

    Some of the online docs say that you can use

    echo <<<END

    all sorts of text and statements...

    END;


    but if the following produces a parse error at line 14 which is the closing
    php tag.

    <?php
    echo <<<TT
    <tr>
    <td>
    <p>1. some text...</p>
    </td>
    <td>
    <p>
    <input type="radio" name="gs.$i" value="1">
    </p>
    </td>
    </tr>
    TT;
    ?>

    Any suggestions, like don't use this tag?

    Thanks, Mike



    ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
  • usenet@isotopeREEMOOVEmedia.com

    #2
    Re: echo &lt;&lt;&lt; tag ... tag;

    On Thu, 4 Aug 2005 09:14:23 -0600, "Michael G" <mike-g@montana.com> wrote:
    [color=blue]
    >Some of the online docs say that you can use
    >
    >echo <<<END
    >
    >all sorts of text and statements...
    >
    >END;
    >
    >
    >but if the following produces a parse error at line 14 which is the closing
    >php tag.
    >
    ><?php
    >echo <<<TT
    > <tr>
    > <td>
    > <p>1. some text...</p>
    > </td>
    > <td>
    > <p>
    > <input type="radio" name="gs.$i" value="1">
    > </p>
    > </td>
    > </tr>
    >TT;
    >?>
    >
    >Any suggestions, like don't use this tag?
    >[/color]

    Just a guess, but it looks like you're trying to reference a PHP variable inside
    the echo?
    name="gs.$i"

    I'd try something like this:

    <?php
    echo <<<TT1
    <tr>
    <td>
    <p>1. some text...</p>
    </td>
    <td>
    <p>
    TT1;

    echo "<input type=\"radio\" name=\"gs." . $i . "\" value=\"1\">";

    echo <<<TT2
    </p>
    </td>
    </tr>
    TT2;
    ?>

    Comment

    • Justin Koivisto

      #3
      Re: echo &lt;&lt;&lt; tag ... tag;

      Michael G wrote:
      [color=blue]
      > Some of the online docs say that you can use
      >
      > echo <<<END
      >
      > all sorts of text and statements...
      >
      > END;
      >
      >
      > but if the following produces a parse error at line 14 which is the closing
      > php tag.
      >
      > <?php
      > echo <<<TT
      > <tr>
      > <td>
      > <p>1. some text...</p>
      > </td>
      > <td>
      > <p>
      > <input type="radio" name="gs.$i" value="1">[/color]

      If $i==7, the result of this will look like:

      <input type="radio" name="gs.7" value="1">

      Probably not what you intended.
      [color=blue]
      > </p>
      > </td>
      > </tr>
      > TT;[/color]

      Make sure this is on column 1 of the line, and there isn't anything
      after it (including whitespace).
      [color=blue]
      > ?>
      >
      > Any suggestions, like don't use this tag?[/color]

      HEREDOC syntax is quite useful in many cases, and I tend to use in cases
      like this where I have a large HTML block to output with a couple
      variables in it.

      --
      Justin Koivisto, ZCE - justin@koivi.co m

      Comment

      • Joachim Weiß

        #4
        Re: echo &lt;&lt;&lt; tag ... tag;

        Hi![color=blue]
        > Any suggestions, like don't use this tag?[/color]
        Your error occurs if the closing
        TT;
        does not start at the very beginning of the line.

        $x= <<<TT
        some text
        TT;

        fails;

        $x= <<<TT
        some text
        TT;

        works!

        to prevent this error because of the autoindent of my editor I prefer a
        coding style like this:

        if(something) {
        $var=
        <<<EOT
        sometext
        sometext
        EOT;
        }


        HIH

        Jo

        Comment

        • Michael Phipps

          #5
          Re: echo &lt;&lt;&lt; tag ... tag;

          > Some of the online docs say that you can use[color=blue]
          >
          > echo <<<END
          >
          > all sorts of text and statements...
          >
          > END;[/color]
          <SNIP>[color=blue]
          > Any suggestions, like don't use this tag?
          >[/color]

          Take a look at some of the templating systems out there - I use Smarty -




          Comment

          Working...