Heredoc
Moderator: General Moderators
test.php:
Output:
Sorry, you'll have to end the heredoc, do the while statement and then start another heredoc.
Code: Select all
<pre>
<?php
$i = 0;
echo <<<EOD
Start Heredoc
Start While Statement:
while ($i <= 10)
{
echo $i++ . "<br>";
}
End While Statment
End Heredoc
EOD;
?>
</pre>Code: Select all
Start Heredoc
Start While Statement:
while (0 <= 10)
{
echo 0++ . "
";
}
End While Statment
End Heredoc<_< *The heredoc god has landed*
Heredoc is meant to output everything that's after it before it sees it's end anchor. How did you expect it to function?
Also you can't do this:
-Nay
Heredoc is meant to output everything that's after it before it sees it's end anchor. How did you expect it to function?
Also you can't do this:
Code: Select all
echo <<< NOO
this is a htmlentities($text) html text!
NOO;-
Straterra
- Forum Regular
- Posts: 527
- Joined: Mon Nov 24, 2003 8:46 am
- Location: Indianapolis, Indiana
- Contact:
Well, the whole point of me using Heredoc is returning multiple lines from a function. The reason I need this is because I am getting information from a database, and it outputs at 3 different times. The first is the HTML tag that tells the browser where to send the information after the user has clicked Submit. The second is the contents of the actual drop-down menu. The third ends the dropdown manu and provided the user with the Submit and Reset buttons.
you could do this:
$string1='';
$string2='';
$string3='';
while(something){
/* make string one that has all the info needed for that print out */
}
while(something){
/* make string two that has all the info needed for that print out */
}
while(something){
/* make string three that has all the info needed for that print out */
}
echo <<<end
<!-- html and the strings -->
end;
$string1='';
$string2='';
$string3='';
while(something){
/* make string one that has all the info needed for that print out */
}
while(something){
/* make string two that has all the info needed for that print out */
}
while(something){
/* make string three that has all the info needed for that print out */
}
echo <<<end
<!-- html and the strings -->
end;
True. But you could do this...Nay wrote:Also you can't do this:Code: Select all
echo <<< NOO this is a htmlentities($text) html text! NOO;
Code: Select all
<?php
$text = htmlentities($text);
echo <<< WHOOHOO
This is my text... {$text} ...good init?
WHOOHOO;
?>