Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 12-01-2011, 04:06 AM   #1
Senior Member
Registered: Dec 2004
Posts: 1,049

Rep: Reputation: 78
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? says that this example document conforms to the XML syntax of HTML5:
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="">
    <title>Example document</title>
    <p>Example paragraph</p>
That page also says this document conforms to the HTML syntax:
<!doctype html>
    <meta charset="UTF-8">
    <title>Example document</title>
    <p>Example paragraph</p>
Note in particular the simplicity of the doctype declaration.

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 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.

Can anyone recommend a good approach to templating? Ideally one that is somewhat well-known to CSS jockeys and that plays nice with Javascript.
Old 12-01-2011, 06:56 PM   #2
Registered: Jun 2006
Location: Karachi, Pakistan
Distribution: OpenSUSE, CentOS, Debian
Posts: 59

Rep: Reputation: 9
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.


doctype, html5, media type, php

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Templating delite Programming 0 10-19-2010 04:39 AM
LXer: Windows 8, Windows Server 2012, and Office 2012: Estimated RTM Dates Surface on LXer Syndicated Linux News 0 01-30-2010 03:30 PM
LXer: Smarty templating and presentation library for PHP LXer Syndicated Linux News 0 12-09-2005 05:53 PM
LXer: Smarty templating and presentation library for PHP LXer Syndicated Linux News 0 12-09-2005 02:36 PM
Creating a PHP templating system - any ideas? vharishankar Programming 1 07-06-2005 10:51 PM > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:01 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration