Reply to Re: serving xhtml with php

Your name:

Reply:


Posted by cwdjrxyz on 07/19/06 01:53

abracad_1999@yahoo.com wrote:
> Is it possible to serve valid xhtml with php?
>
> xhtml requires the 1st line:
> <?xml version="1.0" encoding="iso-8859-1"?>
> But php interprets the opening <? as a php statement.
>
> If I try to echo this in PHP:
> <?php
> echo '<?xml version="1.0" encoding="iso-8859-1"?>';
> ?>
> The closing ?> of the xhtml bit is interpreted as closing the php.
> Thus:
> '; ?>
> is displayed in the browser.
>
> Any way around this?

First you must be certain that your server is set up to deliver true
xhtml. If you use the extension .html you just serve the page as
ordinary html and there is no point in writing the code in xhtml. If
you associate an extension such as .xhtml with the mime type for
xhtml+xml, then you may serve true xhtml using this extension. Then of
course the page can not be viewed by IE6 or IE7, because these outmoded
browsers can not handle true xhtml after all of these years. However
the recent Mozilla family(Firefox, Mozilla, Netscape) and Opera
browsers can handle true xhtml.

Now to your question assuming you are serving true xhtml. See my
example php page at http://www.cwdjr.info/test/PHPxhtml.php . It will
of course not work on IE6 or 7 because it is written and served as true
xhtml 1.1. The secret is that everything above the head tag is written
using php. If a Usenet post properly displays this, the php code used
at the very top of the page to do this is:

<?php
$charset = "iso-8859-1";
$mime = "application/xhtml+xml";
$prolog_type = "<?xml version=\"1.0\" encoding=\"$charset\"
?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd\">\n<html
xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n";
header("Content-Type: $mime;charset=$charset");
header("Vary: Accept");
print $prolog_type;
?>

So I guess you could say that you are using php to solve any possible
php problem. There likely are other ways to do this. This is just the
first way that came to mind since I have used something much like this
before. A very simple php code is used to obtain the time display. If
you have the WMP installed, a button to start a .wma music file appears
at the bottom. The page validates as xhtml 1.1 and css at the W3C, and
if you use the extended interface there you will find that it is being
served with the correct mime type for xhtml.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация