Forum Moderators: coopster

Message Too Old, No Replies

PHP before DOCTYPE = IE6 in quirsk mode. Solutions?

newbie to PHP with doctype / quirks mode question

         

luispunchy

3:09 am on Aug 26, 2006 (gmt 0)

10+ Year Member



I struggled for a good while trying to determine what was causing my otherwise clean CSS/XHTML standards-based page to suddenly display box model problems in IE6. I was using a correct DOCTYPE (XHTML Transitional) - but IE6 was apparently going into quirks mode.

Some research and I rediscovered / remembered that if IE6 sees anything before the DOCTYPE, it goes to quirks mode.

I'm a newbie in PHP - but I'm under the impression that PHP code is REQUIRED to be put at the top of the document, before the DOCTYPE. Is that a fact? Or can I simply put the PHP anywhere in between the 'head' tags and still be safe?

For all intents and purposes, that approach -- putting the PHP after the DOCTYPE, in the header - appears to work. My page renders in standards mode in IE, the page validates... seems fine. But am I missing some other risk, security issues with PHP being in the header for example?

Just wondering... any input is appreciated!

oh yeah... I even went so far to use PHP to write out the DOCTYPE. Again, I'm a newbie to PHP, so is this even making any difference at all? Example:

<?php
print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
?>

Followed by the rest of the PHP, and then the '<html xmlns="http://www.w3.org/1999/xhtml">
<head>' and the rest of the document as usual.

Thoughts?

DanA

8:19 am on Aug 26, 2006 (gmt 0)

10+ Year Member



I'm under the impression that PHP code is REQUIRED to be put at the top of the document, before the DOCTYPE

Not at all.
<?php should not appear in the file served.
If it appears in the code displayed by the browser, you have a configuration problem or a wrong extension or you output control characters...

coopster

12:24 pm on Aug 26, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



... and you can invoke PHP where and when ever you would like. See Escaping from HTML [php.net] for more information.