1685 posts Time is what you desire most, but waste carelessly.
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 50 and 99 items
  • Referred between 100 and 199 users
  • Grew a moustache for the Envato Movember competition
  • Exclusive Author
  • Has been a member for 4-5 years
  • Envato Studio (Microlancer) Beta Tester
  • Europe
+1 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
  • Bought between 100 and 499 items
  • Contributed a Tutorial to a Tuts+ Site
  • Elite Author
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 50 000 and 100 000 dollars
Artillegence says

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

303 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 100 and 1 000 dollars
  • Syrian Arab Republic
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;
1685 posts Time is what you desire most, but waste carelessly.
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 50 and 99 items
  • Referred between 100 and 199 users
  • Grew a moustache for the Envato Movember competition
  • Exclusive Author
  • Has been a member for 4-5 years
  • Envato Studio (Microlancer) Beta Tester
  • Europe
+1 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
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 100 and 1 000 dollars
  • Syrian Arab Republic
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

1685 posts Time is what you desire most, but waste carelessly.
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 50 and 99 items
  • Referred between 100 and 199 users
  • Grew a moustache for the Envato Movember competition
  • Exclusive Author
  • Has been a member for 4-5 years
  • Envato Studio (Microlancer) Beta Tester
  • Europe
+1 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
  • Envato Studio (Microlancer) Beta Tester
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Most Wanted Bounty Winner
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Bought between 10 and 49 items
  • Exclusive Author
+3 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

?>

2954 posts
  • Australia
  • Community Moderator
  • Elite Author
  • Author had a Free File of the Month
  • Most Wanted Bounty Winner
  • Author had a File in an Envato Bundle
  • Has been a member for 5-6 years
  • Contributed a Blog Post
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+10 more
dtbaker Volunteer 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
?>
by
by
by
by
by
by