Specifying a doctype

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Specifying a doctype

Post by Ambush Commander »

This is a sort of a poll, but I don't know what the answers are, so it'll be free response. Suppose you were using a library, which could output certain types of HTML. HTML 4 Strict, Transitional, XHTML 1.0, XHTML 1.1, XHTML 2.0, you name it. And you needed to specify which language you wanted the library to output. How would you prefer to identify it? Would it be...

Full doctype: "-//W3C//DTD XHTML 1.0 Transitional//EN"

Totally new short name system: XHTML 1.0 Transitional; XHTML 1.1 + Legacy; HTML 4.01 Strict...

A bunch of little variables: array('type' => 'XHTML', 'version' => '1.1', 'modules' => array('Legacy')); array('type' => 'HTML', 'version' => '4.01', flavor = 'Transitional');

Something else?

Just quick opinions. What you would find to be most convenient.
User avatar
Nathaniel
Forum Contributor
Posts: 396
Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA

Post by Nathaniel »

I like your "totally new short name system."
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

I'd use a bunch of shorthand names, plus have the ability to override with your own full doctype string.

Maybe the shorthand could take standard arguments...

Code: Select all

setDocType('xhtml'); // sets a default for xhtml, like xhtml 1.0 transitional
setDocType('xhtml','1.0'); // sets a default for xhtml 1.0 (probably transitional - seems popular)
setDocType('xhtml','1.0','Transitional'); // sets the whole thing.
setDocType('-//W3C//DTD XHTML 1.0 Transitional//EN'); // set the whole string
You'd have to match the input args against some preset strings, but it's oh-so friendly to use :-)
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

I used the following in my page generator..

Code: Select all

function _docType($type) {
      $docTypes = array();
      $docTypes['h4.01s'] = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">';
      $docTypes['h4.01t'] = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
      $docTypes['h4.01f'] = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">';
      $docTypes['x1.0s'] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
      $docTypes['xhtml10trans'] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
      $docTypes['x1.0f'] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">';
      $docTypes['x1.1'] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
      return $docTypes[$type];
   }
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Constants for all possible doctypes that can be replaced with full string definitions if necessary.
I don't like new short name because its more to have to learn and understand.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

nickvd: I think your short names are too short. h4.01s? :-P

I'm all for standards compliance, so adhering to the true document type identifiers is nice, but I'm not exactly adhering to the standards. I'm actually using a subset of the functionality that is standard's compliant. So the real name would actually be "XHTML 1.0 Transitional Safe", but I think I'll put safe in another parameter.

Thanks for the input, anyone else have any thoughts?
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Short names as class constants - why let the user make mistakes? ;)

Won't all this have to feed forward into the related HTML syntax? :?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Short names as class constants - why let the user make mistakes?
If I throw an error when they pass a bad short name, isn't that just as good? I'd like to stay away from constants, since define() is not very fast and they look ugly.
Won't all this have to feed forward into the related HTML syntax?
Not sure what you mean by that.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

why not

Code: Select all

class DocTypes
{
    const XHTML_10_STRICT = '...';
....
}
?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

PHP 4. ;-)
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

ah
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Totally new short name system has my vote.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

I use a method similar to Kieran's.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Kieran's idea++
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Custom function with different parameters for different types: 3
Short names, with full doctypes optional: 4

Come on guys, be more decisive!

Jk, jk, I can probably add support for both.
Post Reply