Trying to use a here doc within a switch

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • william c

    Trying to use a here doc within a switch


    I'm trying to use here docs within a switch to output html. The code
    below works (i.e. prints a Foo1 headline below my tab graphic) but if I
    take out the comments and use the entire switch statement I get a parse
    error. I've tried to simplify it down to the bones but can't get it much
    simpler than this...

    Can anybody spot my error?

    thx,

    wmc.





    <?php

    echo '<img border="0" src="images/tab' . $qstring . '.gif" width="570"
    height="40" alt="" usemap="#mapTab s" />';
    echo "\n<map name=\"mapTabs\ ">";

    switch($qstring ) {

    case '1':

    $content1 = <<< END1
    <h1>Foo 1</h1>
    END1;
    echo $content1;
    break;

    /*
    case '2':

    $content2 = <<< END2
    <h1>Foo 2</h1>
    END2;
    echo $content2;
    break;

    case '3':

    $content3 = <<< END3
    <h1>Foo 3</h1>
    END3;
    echo $content3;
    break;
    */
    }
    ?>
  • Ian.H [dS]

    #2
    Re: Trying to use a here doc within a switch

    On Tue, 26 Aug 2003 15:46:01 GMT in
    <message-id:3F4B8071.C7C BE514@williamc. com>
    william c <temp4_NO_SPAM_ @williamc.com> wrote:
    [color=blue]
    > I'm trying to use here docs within a switch to output html. The code
    > below works (i.e. prints a Foo1 headline below my tab graphic) but if
    > I take out the comments and use the entire switch statement I get a
    > parse error. I've tried to simplify it down to the bones but can't
    > get it much simpler than this...
    >
    > Can anybody spot my error?
    >
    > thx,
    >
    > wmc.
    >[/color]


    [ snip ]

    [color=blue]
    > $content1 = <<< END1[/color]
    ^
    ^

    Can't have a space here =)

    [color=blue]
    > <h1>Foo 1</h1>
    > END1;
    > echo $content1;
    > break;[/color]


    [ snip "repetitive of thew above ]


    The same goes for the rest in the code.


    HTH.



    Regards,

    Ian

    --
    Ian.H [Design & Development]
    digiServ Network - Web solutions
    www.digiserv.net | irc.digiserv.ne t | forum.digiserv. net
    Programming, Web design, development & hosting.

    Comment

    • william c

      #3
      Re: Trying to use a here doc within a switch

      [color=blue]
      >[color=green]
      > > $content1 = <<< END1[/color]
      > ^
      > ^
      >
      > Can't have a space here =)
      >[/color]


      ???

      You mean can't have a space here, no?

      END1;
      ^

      The books I'm looking at say you *must* have a space after the <<< and
      before the identifier.

      --wmc.

      Comment

      • Ian.H [dS]

        #4
        Re: Trying to use a here doc within a switch

        On Tue, 26 Aug 2003 19:14:06 GMT in
        <message-id:3F4BB135.907 A0DA@williamc.c om>
        william c <temp4_NO_SPAM_ @williamc.com> wrote:
        [color=blue]
        >[color=green]
        > >[color=darkred]
        > > > $content1 = <<< END1[/color]
        > > ^
        > > ^
        > >
        > > Can't have a space here =)
        > >[/color]
        >
        >
        > ???[/color]


        Hmm.. my apologies for the confusion here William.. I've always used
        heredocs with no space there (<<<EOF etc) but I've just tested and it
        appears you can have a space, or without.. no difference =)

        [color=blue]
        >
        > You mean can't have a space here, no?
        >
        > END1;
        > ^
        >
        > The books I'm looking at say you *must* have a space after the <<< and
        > before the identifier.
        >
        > --wmc.[/color]


        There (' END1;') can't have a space before it, as this produces a 'Parse
        error' (aka: syntax error).

        Apologies for any confusion caused regarding the '<<< END1' part =)



        Regards,

        Ian

        --
        Ian.H [Design & Development]
        digiServ Network - Web solutions
        www.digiserv.net | irc.digiserv.ne t | forum.digiserv. net
        Programming, Web design, development & hosting.

        Comment

        Working...