Skip to content
Advertisement

Why should we separate PHP from HTML

I’m rather new to programming and i know how to separate PHP from HTML, but i would like to know if there is any difference in doing

this:

JavaScript

compared to doing this:

JavaScript

Is there any difference between in performance etc, between splitting the PHP code from the HTML code and just echoing the whole page in php?

Advertisement

Answer

The best practice is not to seperate PHP from HTML, the best practice is to seperate logic from markup.

Also important is coding style. Proper line indentions. Using echo "</div>"; instead of echo"</div>";, valid HTML, not putting variables into quotations:

JavaScript

better (why? see my comment below):

JavaScript

Your whole project gains much quality and worthness just by improving the code, writing clean, readable, maintainable. Imagine you want to change the Text, you would have to add or change lots of echoes.

Code Style Guides > Pear, PSR, Zend <

encourage developers to keep their code readable, valid and cross-browser compatible

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement