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

Trying to use a here doc within a switch

P: n/a

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="#mapTabs" />';
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;
*/
}
?>
Jul 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Tue, 26 Aug 2003 15:46:01 GMT in
<message-id:3F***************@williamc.com>
william c <te************@williamc.com> wrote:
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.
[ snip ]

$content1 = <<< END1 ^
^

Can't have a space here =)

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

[ 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.net | forum.digiserv.net
Programming, Web design, development & hosting.
Jul 16 '05 #2

P: n/a
$content1 = <<< END1

^
^

Can't have a space here =)

???

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.
Jul 16 '05 #3

P: n/a
On Tue, 26 Aug 2003 19:14:06 GMT in
<message-id:3F**************@williamc.com>
william c <te************@williamc.com> wrote:
$content1 = <<< END1 ^
^

Can't have a space here =)

???

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


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.

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.net | forum.digiserv.net
Programming, Web design, development & hosting.
Jul 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.