If you have a very long line with echo, over 400 characters (outputting several html elements), is it okay to use, like 8 separate echo lines just to be easier to edit and see through the code and possibly utilize comments for the parts? I’d add new lines but there is not many real new lines to the HTML source code, it’s like 3 html elements but their attributes are generated in a complex way so creating new lines inside the echo would just screw up the code.
you can use heredoc operators or better to echo only the dynamic parts required rather than outputting whole html string
If you have a very long line with echo, over 400 characters (outputting several html elements), is it okay to use, like 8 separate echo lines just to be easier to edit and see through the code and possibly utilize comments for the parts? I’d add new lines but there is not many real new lines to the HTML source code, it’s like 3 html elements but their attributes are generated in a complex way so creating new lines inside the echo would just screw up the code.you can use something like
echo <<<HTML here here here HTML;
you can use heredoc operators or better to echo only the dynamic parts required rather than outputting whole html string
you can use something like
You told me the same 
Well it’s working, thank you very much guys!
The only minor problem is: I had to prepare the variables firsthand
$id = $my_array[$i]->somethingecho <<<HTML some $id here HTML;putting just
$my_array[$i]->something inside the heredoc resulted in an error for some reason…
Anyway, it looks nice in the .php file, in the html source and the whole thing is working!
you can use heredoc operators or better to echo only the dynamic parts required rather than outputting whole html stringyou can use something likeYou told me the same
Well it’s working, thank you very much guys!
The only minor problem is: I had to prepare the variables firsthand
$id = $my_array[$i]->something
echo <<<HTML some $id here HTML;putting just$my_array[$i]->somethinginside the heredoc resulted in an error for some reason… Anyway, it looks nice in the .php file, in the html source and the whole thing is working!
my Friend
Try something like that
echo <<<HTML
{$my_array[$i]->something}
HTML;
hope that will work 
my FriendTry something like that
echo <<<HTML {$my_array[$i]->something} HTML;hope that will work![]()
It works, thanks! It became convenient to define the variables before, because in my code they are much more complex. And it looks nice to have just things like $id in the heredoc. But will use your method for simpler ones in the future. Good tips here in this topic!
- Microlancer Beta Tester
- Sold between 100 000 and 250 000 dollars
- Most Wanted Bounty Winner
- Author was Featured
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Bought between 10 and 49 items
- Exclusive Author
- Has been a member for 2-3 years
When I have large HTML blocks that I need to output in something like a loop I like to just end the php code and continue after the HTML as if it where inline:
<?PHP $i = 0;
while($i <= 10){
?>
<?PHP $i++;
} // end while
?>
- Grew a moustache for the Envato Movember competition
- Community Moderator
- Contributed a Blog Post
- Author was Featured
- Item was Featured
- Won a Competition
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Has been a member for 4-5 years
Yes never output large html chunks using echo or anything complicated like that. Just close off the PHP tag and use normal HTML .
<?php // any php code here
?>
<div> your html code here </div>
<div> the current year is: <?php echo date("Y");?> </div>
<?php // any more php code
?>
