1768 posts Time is what you desire most, but waste carelessly.
  • Has sold $250,000+ on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Sells items exclusively on Envato Market
+5 more
Firsh says

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.

186 posts
  • Has been part of the Envato Community for over 4 years
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has collected 100+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+4 more
Artillegence says

you can use heredoc operators or better to echo only the dynamic parts required rather than outputting whole html string

303 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $100+ on Envato Market
  • Has collected 1+ items on Envato Market
+2 more
Laith says
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;
1768 posts Time is what you desire most, but waste carelessly.
  • Has sold $250,000+ on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Sells items exclusively on Envato Market
+5 more
Firsh says
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]->something

echo <<<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!

303 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $100+ on Envato Market
  • Has collected 1+ items on Envato Market
+2 more
Laith says
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]->something

echo <<<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!

my Friend

Try something like that


echo <<<HTML

{$my_array[$i]->something}

HTML;

hope that will work :P

1768 posts Time is what you desire most, but waste carelessly.
  • Has sold $250,000+ on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Sells items exclusively on Envato Market
+5 more
Firsh says
my Friend

Try something like that


echo <<<HTML

{$my_array[$i]->something}

HTML;

hope that will work :P

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!

725 posts WordPress Ninja
  • Has referred 1000+ members
  • Has sold $250,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+8 more
TylerQuinn says

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

?>

3263 posts
  • Helps us moderate the forums
  • Has been part of the Envato Community for over 5 years
  • Helped several times protecting Envato Market against copyright violations
  • Won a competition
+15 more
dtbaker Moderator says

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
?>

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by