[SOVLED] A PROBLEM WITH HEREDOC?!?!?!?!?!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

[SOVLED] A PROBLEM WITH HEREDOC?!?!?!?!?!

Post by dull1554 »

heres my code

Code: Select all

$the_num_num = "1";
$the_num = "0";

while($_GET['number_of_links']>$the_num)
{
Print <<< EOS
<tr><a href=$_POST[LU_$the_num_num]>
<td onMouseover='this.bgColor=#C0C0C0' onMouseout='this.bgColor=transparent' width='90' align='center'>
<center><font style='color:black'>$_POST[LT_$the_num_num]</font></center></td></a>
</tr>
EOS;


$the_num_num++;
$the_num++;
}
heres what i need to have

Code: Select all

$the_num_num = "1";
$the_num = "0";

while($_GET['number_of_links']>$the_num)
{

Print <<< EOS
<tr><a href=$_POST['LU_$the_num_num']>//added 2 single quotes
<td onMouseover='this.bgColor=#C0C0C0' onMouseout='this.bgColor=transparent' width='90' align='center'>
<center><font style='color:black'>$_POST[LT_$the_num_num]</font></center></td></a>//added 2 single quotes
</tr>
EOS;


$the_num_num++;
$the_num++;
}
when i try the second bit of code i get this error

Code: Select all

Parse error: parse error, unexpected T_VARIABLE, expecting ']' in c:\program files\apache group\apache\htdocs\test\menu\step3.php on line 22
i need to be able to have those quotes in there, but if i put them there everything goes all to hell
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Re: A PROBLEM WITH HEREDOC?!?!?!?!?!

Post by Straterra »

dull1554 wrote:heres my code

Code: Select all

$the_num_num = "1";
$the_num = "0";

while($_GET['number_of_links']>$the_num)
{
Print <<< EOS
<tr><a href=$_POST[LU_$the_num_num]>
<td onMouseover='this.bgColor=#C0C0C0' onMouseout='this.bgColor=transparent' width='90' align='center'>
<center><font style='color:black'>$_POST[LT_$the_num_num]</font></center></td></a>
</tr>
EOS;


$the_num_num++;
$the_num++;
}
heres what i need to have

Code: Select all

$the_num_num = "1";
$the_num = "0";

while($_GET['number_of_links']>$the_num)
{

Print <<< EOS
<tr><a href=$_POST['LU_$the_num_num']>//added 2 single quotes
<td onMouseover='this.bgColor=#C0C0C0' onMouseout='this.bgColor=transparent' width='90' align='center'>
<center><font style='color:black'>$_POST[LT_$the_num_num]</font></center></td></a>//added 2 single quotes
</tr>
EOS;


$the_num_num++;
$the_num++;
}
when i try the second bit of code i get this error

Code: Select all

Parse error: parse error, unexpected T_VARIABLE, expecting ']' in c:\program files\apache group\apache\htdocs\test\menu\step3.php on line 22
i need to be able to have those quotes in there, but if i put them there everything goes all to hell

Try this

Code: Select all

<?php
$the_num_num = "1";
$the_num = "0";

while($_GET['number_of_links']>$the_num)
{
Print
?>
<tr><a href="<?php echo $_POST['LU_$the_num_num']; ?>">
<td onMouseover='this.bgColor=#C0C0C0' onMouseout='this.bgColor=transparent' width='90' align='center'>
<center><font style='color:black'><?php echo $_POST['LT_$the_num_num']; ?></font></center></td></a>
</tr>
<?php
$the_num_num++;
$the_num++;
}
?>
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

i hate to say it but that did not work either, i just don't understand what i have to do to get this to work correctly
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

What error did you get when you used my code?
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

Code: Select all

Parse error: parse error, unexpected '<' in c:\program files\apache group\apache\htdocs\test\menu\step3.php on line 22
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

may the force be with you
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

Code: Select all

<?php 
$the_num_num = "1"; 
$the_num = "0"; 

while($_GET['number_of_links']>$the_num) 
{ 
?>
<tr><a href="<?php echo $_POST['LU_$the_num_num']; ?>"> 
<td onMouseover='this.bgColor=#C0C0C0' onMouseout='this.bgColor=transparent' width='90' align='center'> 
<center><font style='color:black'><?php echo $_POST['LT_$the_num_num']; ?> </font></center></td></a> 
</tr> 
<?php 
$the_num_num++; 
$the_num++; 
} 
?>
Try this.

NOTE : I eddited the

Code: Select all

&lt;tr&gt;&lt;a href="&lt;?php echo $_POST&#1111;'LU_$the_num_num']; ?&gt;"&gt;
Line from post..Make sure you use this line!!
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

thanks, its a bit closer
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

What other errors?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Personally I don't like mixing up html with php.

For the sake of clarity it's important to keep presentation separate from the task of defining vars to be output on a page: eg php scripts do all the business logic first, then print vars by including html templates.

Mixing html up with php also limits your output options. If instead your script defines a bunch of unformatted vars, you are free to output them in any format you like.

And it's hard to work on page layout & graphical design without user-friendly, script-free templates.
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

Yeah, but I personally find it easer to mix PHP and HTML..I use a program that syntax highlited both PHP and HTML, so getting mixed up isn't really a problem for me personally.
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Wondering why Nay hasn't seen this post yet .. he'll school us on heredoc.
User avatar
devork
Forum Contributor
Posts: 213
Joined: Fri Aug 08, 2003 6:44 am
Location: p(h) developer's network

Post by devork »

btw where is nay :roll:
wake up nay.
or you want someone else to answer it?

Code: Select all

<?php
$collections =<<<EOD
Your html goes here
EOD;
?>
this is the example I refer while using heredocs. :)
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

You need not fear now, the master has come :). You can't print arrays like that in heredoc. Use { and } for arrays. Example:

Wrong:

Code: Select all

<?php

echo <<< THAT
$_POST['name']
THAT;

?>
Right:

Code: Select all

<?php

echo <<< THAT
{$_POST['name']}
THAT;

?>
Got me? ;)

On the other note, it also can be used with variables when you want to print somewhat as:

Code: Select all

<?php

$item = "butt";
$action = "burn";

echo <<< THAT
my {$item}'s {$action}ed <_<
THAT;

// which will output: my butt's burned <_<

?>
-Nay
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

lol..i knew you couldt resist a heredoc topic nay :P
Post Reply