PHP doctypes, media types, charsets, and templating engines for 2012
Forgive me if this thread is too broad....
As I am about to embark on the construction of some new websites built on PHP, I would like to make them as modern as possible. It's been awhile since I built any from scratch so I thought I'd ask the community about a few things so as to keep current with what the kids are doing these days.
1 - XHTML or HTML?
w3.org says that this example document conforms to the XML syntax of HTML5:
Does anyone have any anecodotes about why they chose XHTML vs. HTML or vice versa?
2 - HTML4 or HTML5?
It seems pretty clear to me that we should try to use the latest, but I worry about old browsers and wonder how they might respond to the extremely simple doctype declaration (what with no DTD and all).
3 - What media type?
The character encoding advice from w3.org says that HTML documents need either text/html media type or text/html-sandboxed media type. I find myself wondering under what conditions one would use the sandbox type and what protections this might bring me.
XHTML documents need either application/xhtml+xml or application/xml media type.
And how do we deliver these media types? Can we rely on Apache or should we always take care to use the [man]header[/man function?
4- What character encoding?
I've noticed that everyone seems to be using UTF-8 these days because it supports a wide range of languages and is compatible with most ASCII text you see (with some problems when extended ASCII is used -- wired I'm looking at you). Does anyone have trouble specifying the encoding with their text editors these days? When serving these documents, how do we specify the charset?
* using [man]header[/man] and declaring content-type?
* Use a Byte-Order-Mark (BOM) in the file itself?
* Using a meta element with a charset attribute that specifies the encoding within the first 1024 bytes of the document?
5 - Template Engines: How do we separate PHP logic from HTML and styling?
Obviously it's good to separate your application and business logic from its presentation -- this makes it easy to output your content to different delivery platforms such as desktop/mobile phone/tablet. It also makes it easy to re-style your entire site without having to edit your primary logic files.
On the other hand, template engines often require extra steps to package up your data in an array or other merge format so that it can be handed to a template engine and one often has to learn some bizarre new looping syntax when dealing with data collections (or nested data collections -- *shudder*). There are also performance considerations -- merging data with some kind of parsed template can affect server peformance.
1. and 2. html 5 is what's popular now so go with that. The second example.
3. and 4. Don't worry about media type. Apache takes care of that. If you are serving multiple languages you can go with UTF8.
5. PHP is a templating language in and of itself. You get extra points if you manage to restrict PHP in your templates to just echo statements. But most CMS don't do even that so it's not a big deal if you have to use a loop or a few if statements in there. Avoid templating languages like smarty. They just add to the complexity.
|All times are GMT -5. The time now is 09:17 PM.|