View Full Version : PHP is displayed to page because Doctype = Strict

11-28-2010, 04:35 AM
I am working on a Contact Form in my .php file. I have always worked with loose doctypes, however, today I am using strict. I have my php above my html, and none of the code runs. Instead, it just displays some of the Echos to the page (these aren't even called yet). Also, in my form, I have the following:

<INPUT NAME="Name" SIZE="30" value="<?php echo $Name; ?>">

On the page inside the field, it is displaying: <?php echo $Name; ?>

What is going on here and how can I fix this issue?

Yes, the pages are .php
Here is the doctype:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Any input appreciated

11-28-2010, 07:23 AM
Doctype strict is, well 'strict', it doesn't tolerate any bad markup, by it's definition, this is bad: <INPUT NAME, should be all lower case inside tags, so for starters, run the page through the validator, also you may have a missing " or ' here or there. And read up on the allowed markup a bit. And that doesn't account for how browsers render it, some may be more tolerant than others.

11-28-2010, 09:44 AM
Your problem has nothing to do with the doctype in use. If php code is being displayed raw, you have a syntax error somewhere. Enable error reporting and see what the problem is. Also, as DrDos mentioned, the XHTML strict doctype requires that all tags are in their correct case. XML is case sensitive. It's only the fact that you are obviously serving it as text/html instead of its correct mimetype which is allowing it to display at all. The browser would be halting during parsing otherwise.