Reputation: 253
What are the advantages and disadvantages of separating PHP and HTML content?
Upvotes: 1
Views: 393
Reputation: 20721
Separating program logic (the PHP part) from presentation (the HTML part) is beneficial for several reasons:
Upvotes: 1
Reputation: 363
if u want to divide the php code and html, use any php frameworks, such as codeigniter, cakephp, zend, yii, etc., the main advantage is, if ur going to change the site design not your functionality, at that time it will be very useful and also we can develop the code in reusable manner.
Upvotes: 0
Reputation: 100
The main reason is your code will be ugly if you merge those php (business logic) with the html (presentation) together, which in turn become hard to read and become hard to maintain. It won't be a problem if your web application is a simple one. But if it's a enterprise scale project, maintaining this merged code will be a nightmare for anyone.
Beside, the kind of programming you do for each part and sometimes the language you do it in are different. Separating the two allows one to use the best tools for that particular part.
source: http://www.paragoncorporation.com/ArticleDetail.aspx?ArticleID=21
Upvotes: 0
Reputation: 9671
HTML is just for the representation of your results / forms etc (your view), see MVC pattern for more info.
If you separate it from your business logic, you'll be able to generate other views easily (e.g. JSON for Javascript).
If you're using a templating engine as well, your HTML/CSS gurus can work on the look and feel independently as well.
Upvotes: 1
Reputation: 485
There is a great advantage to separating the two because you can edit html code without breaking the PHP code. Smarty is a good template engine to learn.
Upvotes: 0
Reputation: 2202
The advantages mostly pertain to code readability, which in large applications plays a huge part in the maintenance of the application.
The disadvantages are that it sometimes makes advanced functionality hard to execute. Most of the time, it can be done and still keep the two separate, but it's often much simpler and easier to just insert php snippets into html code or vice-versa if its just a small amount of code.
It's a trade off between ease of execution in certain cases and readability. For the most part, I would recommend trying to keep them separate.
Upvotes: 2