Best practice for HTML head in PHP

前端 未结 4 2203
不思量自难忘°
不思量自难忘° 2021-01-01 22:36

I currently have a very simple page, with some more complicated backend. I\'ve always done this the same way, but I feel it\'s not right. But I haven\'t come up with much us

4条回答
  •  既然无缘
    2021-01-01 23:23

    What I have done is make header and footer functions that take an array as a parameter, and the array may contain optional elements, so you would pass in the title, etc. to the header function.

    I think one thing you will find that is "generally accepted" is to use PHP more and more as a program, and less to drop out of html when you need dynamic content only. In other words, writing everything as a program that outputs html, not as a mix of html and php (opening and closing the PHP tags).

    In this model, many websites only have one "index.php" and that actually generates all the pages (often from a database). But if you've only got handful of pages, then each being it's own php page with shared header and footer functions is a fine way to go, IMHO.

提交回复
热议问题