Is it correct to mix PHP code with HTML?

Asked

Viewed 92 times

2

I am restarting my studies in the area of IT and I have this doubt. In the course I’m doing the examples show the php code mixed and inserted into the html code. Is that really how it works in practice? I have a flea behind my ear telling me that this is not good practice. If so, how do the back and front developers share the code?

My question is not to know what Front and Back is, is to understand why the php code is together with the html. If they do it even in the day-to-day of the companies.

  • Do you really want to know at PHP or language independent level? Back and front can also be applied in other contexts, such as mobile or even desktop.

  • I believe that for my level would further elucidate the question of knowing the level of php

  • 1

    Have a foreach or even a if simple within html tags has no problem. The real problem is that giant 1200 script with business logic, presentation and who knows what else.

  • In some cases you will notice that merging PHP code with HTML can help you. But as @rray said, the problem is in excess. In wanting to transfer class responsibilities to your PHP page that contains HTML and turn it into a giant, hard-to-understand file. I particularly prefer to separate the maximum and make the interactions of PHP pages with HTML templates via javascript. But this is not a rule and you can choose what is best for you or your project!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.