on-internet
← Community

What is the best practice to use when using PHP and HTML?

Stack Overflow ·

I have been designing websites for a while now, but there is one thing that I have never been quite sure of when using PHP and HTML. Is it better to have the whole document in PHP and echo HTML like so: <?php doSomething(); echo "<div id=\"some_div\">Content</div>"; ?> Or have a HTML file like so and just add in the PHP: <html> <body> <?php doSomething(); ?> <div id="some_div">Content</div> </body> </html> It seems tidier to echo HTML, especially if lots of PHP gets used throughout the page, but doing so loses all formatting of the HTML i.e. colors in the IDE etc.

Comments

Sign in or sign up to comment and upvote.

No comments yet.