Page 1 of 1

Which Doctype should I go with? (transitional/xhtml...)?

Posted: Wed Aug 23, 2006 11:27 am
by matt1019
Hello Guys,

Just wanted to check and see if someone can point to a good resource on the internet that explains which doctype to use if you have used html in php with these kinds of tags:

Code: Select all

<img src='images/next.gif'>
or

Code: Select all

<div id='tagit'>
notice the single quotes....


I tried using this line:

Code: Select all

echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html>
<head>
...
</head>";
but this gives me the following types of errors:
Result: Failed validation, 300 errors
Error Line 5 column 72: end tag for "meta" omitted, but OMITTAG NO was specified.

...ype' content='text/html; charset=iso-8859-1'>

Info Line 5 column 0: start tag was here.

<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>

etc. etc. etc.


then I tried this:

Code: Select all

echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">
<html>
<head>
...
</head>";
This gave me 122 errors:
Result: Failed validation, 122 errors
such as:
Error Line 17 column 6: end tag for element "HEAD" which is not open.

</head>

Error Line 18 column 50: document type does not allow element "BODY" here.

<body bgcolor='#FFFFFF' text='#000000' id='type-c'>
Now, I know 122 is much better than 300 errors, but is 4.01 transitional/loose.dtd the correct type to be using?

Thanks guys,

-Matt

Posted: Wed Aug 23, 2006 11:41 am
by matthijs
I would go for a strict doctype. Whether it's html or xhtml doesn't really matter. Well, ok maybe html 4 strict is a better choice. But that will depend on many factors.

You can read more here and here

It's quite a discussion though. At first everyone following the webstandards movement switched to xhtml. Proudly showing buttons xhtml/css. But lately many people have returned to html strict, realising that serving xhtml as text/html is kind of silly. Personally I'm used to xhtml strict, so that's a bit easier for me. But html 4 strict is just as fine for me.

Posted: Wed Aug 23, 2006 1:37 pm
by Ambush Commander
Since you're not building it from the ground up, I'd take small steps and start by making your docs HTML 4.01 Transitional compliant.

Your real question, however, about double-quotes and single-quotes, no the doctype doesn't matter. Single quotes are always valid, although personally I prefer using double-quotes (if you've got lots of inline HTML in your PHP, that's something else that you probably should fix by moving it to templates).

Posted: Wed Aug 23, 2006 1:55 pm
by bg
HTMLTidy is your friend. If you use jEdit, its got a tidy plugin built-in to format your html according to the specified DTD. (jEdit is awsome btw, highly recommended).

Another thing you might wanna try is not having php output any html at all. Instead, have the document all html and insert inline PHP tags where necessary. If you do need php to generate html, make sure it is generating both the opening tag and the ending tag. o One, to eliminate confusion, and two, so that a formatter or checker can still validate even though there is PHP involved.

Personally, I would write xhtml strict. It will allow the most consistent rendering of your website between browsers.

Posted: Wed Aug 23, 2006 2:46 pm
by matthijs
Personally, I would write xhtml strict. It will allow the most consistent rendering of your website between browsers
I don't think this is true. But if you can convince me otherwise, you're welcome to do of course.

It's even the case that if you serve real XHTML as application/xhtml+xml, you'll encounter many problems trying to even getting your pages rendered at all. One small mistake and you get nothing but a yellow screen of death. Some browsers don't support xhtml at all (IE). well read all about it here.

Posted: Wed Aug 23, 2006 3:45 pm
by RobertGonzalez
I like to use strict. Either HTML or XHTML strict, but always strict. And I never use single quotes when wrapping HTML tag elements. And... oh never mind, I pretty much answered the original question.

Posted: Wed Aug 23, 2006 6:12 pm
by Ollie Saunders
XHTML 1.0 strict for me. Don't know the difference between 1.0 and 1.1.
jEdit is awsome btw
I have to try that.

Posted: Wed Aug 23, 2006 7:29 pm
by matt1019
thanks guys for the replies with help/suggestions/tips/and recommendations!!

Thank god (and also to Ambush Commander for letting me know that single quotes will not be an issue) I dont have to go through lines and lines of code to change it back to double quotes...

As far as strict/loose go: I am going to go with HTML strict. Have read up on the differences (thanks to matthijs in the first reply with the links to read-up on ;))

@bg: thanks, I will def. take a look at those editors. I am getting kind of bored with word pad anyways.... might as well switch to something that will help along the way too.

@Everah: "And I never use single quotes when wrapping HTML tag elements" I know... should have followed this BEFORE... I guess I learned the hard way, huh?

But, I am sure i wont make this mistake twice.... (wrapping HTML tag elements with single quotes)

@ole: thanks. :)

Thanks once again, guys.

-Matt