Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > serving xhtml with php

Reply
Thread Tools

serving xhtml with php

 
 
abracad_1999@yahoo.com
Guest
Posts: n/a
 
      07-18-2006
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?

 
Reply With Quote
 
 
 
 
flamer die.spam@hotmail.com
Guest
Posts: n/a
 
      07-18-2006


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?


Is it your server? turn off short_tags in your php conf. that way you
can only use <?php not <?

Flamer.

 
Reply With Quote
 
 
 
 
Chung Leong
Guest
Posts: n/a
 
      07-18-2006

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?


echo '<?xml ... ?' . '>';

 
Reply With Quote
 
Chung Leong
Guest
Posts: n/a
 
      07-18-2006
Chung Leong wrote:
> 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?

>
> echo '<?xml ... ?' . '>';


Wait a minute. That's not supposed to be necessary. PHP knows when it's
inside a string.

 
Reply With Quote
 
boclair
Guest
Posts: n/a
 
      07-18-2006
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?
>

Perhaps
<?php
.......
?>
<?xml version="1.0" encoding="iso-8859-1"?>

Louise
 
Reply With Quote
 
Rik
Guest
Posts: n/a
 
      07-18-2006
Chung Leong wrote:
> Chung Leong wrote:
>> wrote:
>>> 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?

>>
>> echo '<?xml ... ?' . '>';

>
> Wait a minute. That's not supposed to be necessary. PHP knows when
> it's inside a string.



You are right.
<?php
echo '<?xml version="1.0" encoding="iso-8859-1"?>';
?>
Works perfectly here (tested with shorttags on which are usually off).

Grtz,
--
Rik Wasmus



 
Reply With Quote
 
cwdjrxyz
Guest
Posts: n/a
 
      07-19-2006

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.

 
Reply With Quote
 
Kimmo Laine
Guest
Posts: n/a
 
      07-19-2006
"cwdjrxyz" <> wrote in message
news: oups.com...
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.


Really? Are you talking about IE7 for sure now? It's not even out yet and
you claim it's "outmoded" and can't handle xml "after all these years"? Did
you mean IE5?

I found a pretty decent article that explains the situation with IE7 and
xhtml: http://blogs.msdn.com/ie/archive/2005/09/15/467901.aspx I recommend
reading it.

Personally I think it's good that the IE people won't even try implementing
something as strict as xml on a buggy and loose parser that IE has always
had. I got the picture from Wilson's article that they're gonna start from
scratch after IE7 and make finally something worthy of the xml parser, not
just (try to) fix quick-and-dirty the current html parser.

Bottom line is that IE sucks more than anything that has ever sucked before,
and it will remain like that all eternity, but there's a chance 7 won't suck
just as much 6 does.

--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
| Gedoon-S @ IRCnet | rot13()


 
Reply With Quote
 
Noodle
Guest
Posts: n/a
 
      07-19-2006
It shouldn't need the line:
<?xml version="1.0" encoding="iso-8859-1"?>
for it to validate as XHTML (I think its just recommended).

You could just omit it if your server/php config won't let you include
it.



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?


 
Reply With Quote
 
unwiredbrain@gmail.com
Guest
Posts: n/a
 
      07-19-2006
Noodle wrote:
> It shouldn't need the line:
> <?xml version="1.0" encoding="iso-8859-1"?>
> for it to validate as XHTML (I think its just recommended).
>
> You could just omit it if your server/php config won't let you include
> it.

Yes, that's correct. It /should/ be used, but it's not /necessary/ i.e.
normative. So you can just omit it, your pages will validate anyway.
Moreover, some browsers fall in quirks mode if you add it: check
http://www.quirksmode.org for more specific infos.

(As we say in sicily) Baciamo le mani
--
Massimo "unwiredbrain" Lombardo

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Training Institute In Delhi, Live Projects on PHP. Short TermPHP Courses, PHP Scripts, PHP Training with Live Projects. Rajive Narain Java 0 09-18-2009 10:47 AM
Serving XHTML documents as XHTML does weird things. -Lost Javascript 7 06-20-2007 04:50 AM
Webrick serving php pages? Marc Heiler Ruby 2 07-29-2006 05:31 PM
Solving script and other problems for serving true xhtml 1.1 cwdjrxyz@yahoo.com Javascript 1 08-27-2005 10:31 PM
serving pages in ASP ala PHP -[ CaMeL ]- a55m0nk ASP General 3 10-27-2003 09:36 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57