1829 posts Time is what you desire most, but waste carelessly.
  • Author Level 9
  • Elite Author
  • Exclusive Author
  • Trendsetter
+9 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.

191 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Author Level 8
  • Collector Level 4
+8 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
  • 5 Years of Membership
  • Affiliate Level 1
  • Author Level 2
  • Collector Level 2
+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;
1829 posts Time is what you desire most, but waste carelessly.
  • Author Level 9
  • Elite Author
  • Exclusive Author
  • Trendsetter
+9 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
  • 5 Years of Membership
  • Affiliate Level 1
  • Author Level 2
  • Collector Level 2
+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

1829 posts Time is what you desire most, but waste carelessly.
  • Author Level 9
  • Elite Author
  • Exclusive Author
  • Trendsetter
+9 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
  • Affiliate Level 7
  • Author Level 9
  • Beta Tester
  • Collector Level 2
+11 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

?>

5441 posts
  • Author Level 11
  • Moderator
  • Winner
  • 6 Years of Membership
+20 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
?>
by
by
by
by
by
by