Page 1 of 2
Specifying a doctype
Posted: Sat Feb 10, 2007 10:44 pm
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.
Posted: Sat Feb 10, 2007 11:12 pm
by Nathaniel
I like your "totally new short name system."
Posted: Sat Feb 10, 2007 11:19 pm
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

Posted: Sat Feb 10, 2007 11:58 pm
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];
}
Posted: Sun Feb 11, 2007 3:01 am
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.
Posted: Sun Feb 11, 2007 11:52 am
by Ambush Commander
nickvd: I think your short names are too short. h4.01s?
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?
Posted: Mon Feb 12, 2007 3:13 am
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?

Posted: Mon Feb 12, 2007 3:22 pm
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.
Posted: Mon Feb 12, 2007 3:28 pm
by Ollie Saunders
why not
Code: Select all
class DocTypes
{
const XHTML_10_STRICT = '...';
....
}
?
Posted: Mon Feb 12, 2007 3:29 pm
by Ambush Commander
PHP 4.

Posted: Mon Feb 12, 2007 3:32 pm
by Ollie Saunders
ah
Posted: Mon Feb 12, 2007 4:32 pm
by RobertGonzalez
Totally new short name system has my vote.
Posted: Mon Feb 12, 2007 4:32 pm
by daedalus__
I use a method similar to Kieran's.
Posted: Mon Feb 12, 2007 4:34 pm
by Luke
Kieran's idea++
Posted: Mon Feb 12, 2007 4:42 pm
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.