I’ve heard it’s a bad practice to echo dynamic HTML content through PHP. But what are the alternatives, in case you need it, like, f.e. a navigation menu on a website, repeated in every page?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I suspect that this was meant as an advice against “hard-coding” the views in your PHP scripts, and rather separate your concerns by introducing something like an MVC approach. The gains in terms of maintainability and clarity of the code are significant, and in that respect it is a good advice.
That is really just an abstraction, though. At some point PHP has to output the HTML to the browser.
So, outputting dynamic HTML content is an integral part of PHP, but there are worse and better ways of doing it, and hard-coding HTML strings within
echostatements is generally not the best way of doing it. Introduce a template engine and separate views and business logic, and you’re likely better off.