serving xhtml with php

A

abracad_1999

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?
 
G

Guest

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.
 
C

Chung Leong

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 ... ?' . '>';
 
B

boclair

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
 
R

Rik

Chung said:
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,
 
C

cwdjrxyz

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.
 
K

Kimmo Laine

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.
 
N

Noodle

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.
 
U

unwiredbrain

Noodle said:
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
 
C

cwdjrxyz

Kimmo said:
If

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 said true xhtml rather than xml as you see from your quote above. You
could also include IE5 and all lower IEs if you wish but it hardly
would seem necessary if the IE6 does not support true xhtml. The
article quoted just below and many other reports confirm that IE7 will
not support true xhtml based on the mime type application/xhtml+xml. Of
course there could be a last minute change, but considering that the
browser would require extreme rewriting, this seem to be highly
unlikely unless the introduction of the IE7 id delayed for many months
and Microsoft perhaps hires some people away from Mozilla and Opera who
have experience in introduction of true xhtml.
 
C

Chung Leong

What is the point of XHTML anyway? To me it always seems an exercise in
vanity. I was looking at the FAQ at the W3C and the answer to the
question as to why XHTML is necessary goes something like "Well, we had
this workshop a few years ago and everyone there thought it's a good
idea."
 
C

cwdjrxyz

Chung said:
What is the point of XHTML anyway? To me it always seems an exercise in
vanity. I was looking at the FAQ at the W3C and the answer to the
question as to why XHTML is necessary goes something like "Well, we had
this workshop a few years ago and everyone there thought it's a good
idea."

Of course one is still free to write code in an html level as low as
3.2 which still can be validated at the w3c and which seems to be
supported by most recent computer browsers also. The importance of
xhtml/xml is that a very large number of smaller devices now support
xml and sometimes not html. Thus traditional computer browsers need to
be brought in line to allow easy exchange of data between many
different types of devices. If I were teaching a programming course, I
would require that all programs be written in xhtml 1.1 as well as html
4.01 strict or be given a reason of why a program can not be written
in xhtml 1.1. I would also give any program that did not completely
validate at the w3c html/xhtml and css validators a grade of zero.
Fortunately for many future students, I am very unlikely to ever teach
programming :) .
 
G

Geoff Berrow

If I were teaching a programming course, I
would require that all programs be written in xhtml 1.1 as well as html
4.01 strict

Why both? They are two separate things used for different reasons.
 
C

Chung Leong

cwdjrxyz said:
Of course one is still free to write code in an html level as low as
3.2 which still can be validated at the w3c and which seems to be
supported by most recent computer browsers also. The importance of
xhtml/xml is that a very large number of smaller devices now support
xml and sometimes not html. Thus traditional computer browsers need to
be brought in line to allow easy exchange of data between many
different types of devices.

I'm a believer in democracy and the free market. The idea that we
should all adopt a technology because a bunch of guys in a room think
it's a good thing offends me.

Having the whole world adjust to the limitation of a few devices is a
preposterous misallocation of human resource. If some devices can't
handle HTML, screw them. People will buy competing products that can.
 
C

cwdjrxyz

My complete statement was:

"If I were teaching a programming course, I
would require that all programs be written in xhtml 1.1 as well as html
4.01 strict or be given a reason of why a program can not be written
in xhtml 1.1."
Why both? They are two separate things used for different reasons.

An xhtml program can be pure html, pure xml, or a combination of both.
Thus an xhtml program that has no xml only functions in some cases is
about the same as an html 4.01 strict program with the addition of a
few special things, such as closing everything, using lower case
characters only, etc. In that case the html 4.01 strict page works just
as well and does not require a special version for IE. However some
xhtml pages may contain xml content that is best handled by xhtml, or
in some cases xml only. Thus I needed an exception and would require
the reason for the exception to see if it was understood why the
exception was necessary, or far more practical. I should also have
included the inverse case when the xhtml page can not be written as
html 4.01 strict without undue complication, often because of the xml
content in the xhtml page.
 
G

Geoff Berrow

An xhtml program can be pure html, pure xml, or a combination of both.
Thus an xhtml program that has no xml only functions in some cases is
about the same as an html 4.01 strict program with the addition of a
few special things, such as closing everything, using lower case
characters only, etc. In that case the html 4.01 strict page works just
as well and does not require a special version for IE. However some
xhtml pages may contain xml content that is best handled by xhtml, or
in some cases xml only. Thus I needed an exception and would require
the reason for the exception to see if it was understood why the
exception was necessary, or far more practical. I should also have
included the inverse case when the xhtml page can not be written as
html 4.01 strict without undue complication, often because of the xml
content in the xhtml page.

A lot of people are jumping on the XHTML bandwagon for no better reason
than they think newer==better. I know you're not one of them. I just
wanted to make the point that the doctype should be the one that is most
appropriate, not one that is being used just because it is fashionable.
 
N

Nikita the Spider

Chung Leong said:
What is the point of XHTML anyway? To me it always seems an exercise in
vanity. I was looking at the FAQ at the W3C and the answer to the
question as to why XHTML is necessary goes something like "Well, we had
this workshop a few years ago and everyone there thought it's a good
idea."

Hi,
See the active thread in alt.html entitled "XHTML vs HTML", especially
the part about how this question usually ignites flame wars.
 
W

william.clarke

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?

There is no requirements to have "<?xml version="1.0"
encoding="iso-8859-1"?> " at the top of an XHTML page, it is required
for XML though. What is required is:

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

Read the W3C tutorials... http://www.w3schools.com/xhtml/xhtml_dtd.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top