Serving XHTML and self
I am trying to follow the xhtml 1.0 strict standard as I am creating my website. Right now, validator.w3.org validates my document as valid, following the XHTML 1.0 Strict standard. Here is a code-example:
<div style="color:#f00"><div style="color:#00f" />Text should be red and not blue</div>
Unfortunately, Firefox, Chrome and Internet Explorer parses the document incorrectly: They all seem to ignore the closing statement of my self-closing tags (mostly
, and some other tags), thus rendering the site incorrectly, with the text being blue. if i replace tags with , it all looks fine. I read about it and according to xml document, including xhtml, can be self-closedHere is the important header information that comes with the document:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
Apache2 itself still sends Content-Type text/html, as I haven't figured out yet how to overwrite the .php mime type, though the info in
should overrule that either way.How can I use self-closing tags such as
with them being parsed correctly by common browsers?XHTML is HTML using XML and HTML does not have self-closing tags like you show. This works in XHTML but not HTML and, so far, you are not serving as application/xml+xhtml.
The content-type meta tag does not affect how the server serves the page and is for offline use only. So you must either set it in the server or with PHP, in your case.
Sending this with php:
<?php
header('Content-Type: application/xhtml+xml;');
?>
That's how you override standard headers using PHP. You have to be careful, because header()
only works if no output has been sent yet. This means you must not place anything before the <?php
part, header will not work as your server will already have sent both the headers and whatever content there was.
下一篇: 服务XHTML和自我