By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,203 Members | 1,623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,203 IT Pros & Developers. It's quick & easy.

serving xhtml with php

P: n/a
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?

Jul 18 '06 #1
Share this Question
Share on Google+
30 Replies


P: n/a


ab**********@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?
Is it your server? turn off short_tags in your php conf. that way you
can only use <?php not <?

Flamer.

Jul 18 '06 #2

P: n/a

ab**********@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?
echo '<?xml ... ?' . '>';

Jul 18 '06 #3

P: n/a
ab**********@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?
Perhaps
<?php
.......
?>
<?xml version="1.0" encoding="iso-8859-1"?>

Louise
Jul 18 '06 #4

P: n/a
Chung Leong wrote:
ab**********@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?

echo '<?xml ... ?' . '>';
Wait a minute. That's not supposed to be necessary. PHP knows when it's
inside a string.

Jul 18 '06 #5

P: n/a
Rik
Chung Leong wrote:
Chung Leong wrote:
>ab**********@yahoo.com 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

Jul 18 '06 #6

P: n/a

ab**********@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.

Jul 19 '06 #7

P: n/a
"cwdjrxyz" <sp*******@cwdjr.infowrote in message
news:11**********************@p79g2000cwp.googlegr 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
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Jul 19 '06 #8

P: n/a
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.

ab**********@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?
Jul 19 '06 #9

P: n/a
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

Jul 19 '06 #10

P: n/a

Kimmo Laine wrote:
"cwdjrxyz" <sp*******@cwdjr.infowrote in message
news:11**********************@p79g2000cwp.googlegr 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 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.
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.
Jul 19 '06 #11

P: n/a
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."

Jul 19 '06 #12

P: n/a

Chung Leong wrote:
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 :-) .

Jul 19 '06 #13

P: n/a
Message-ID: <11**********************@h48g2000cwc.googlegroups .comfrom
cwdjrxyz contained the following:
>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.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 19 '06 #14

P: n/a
cwdjrxyz wrote:
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.

Jul 19 '06 #15

P: n/a

Geoff Berrow wrote:
Message-ID: <11**********************@h48g2000cwc.googlegroups .comfrom
cwdjrxyz contained the following:
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
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.

Jul 19 '06 #16

P: n/a
Message-ID: <11**********************@b28g2000cwb.googlegroups .comfrom
cwdjrxyz contained the following:
>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.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 19 '06 #17

P: n/a
On 2006-07-19, Geoff Berrow wrote:
Message-ID: <11**********************@h48g2000cwc.googlegroups .comfrom
cwdjrxyz contained the following:
>>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.
Why either? They are not programming languages.

--
Chris F.A. Johnson <http://cfaj.freeshell.org>
================================================== =================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Jul 19 '06 #18

P: n/a
In article <11**********************@h48g2000cwc.googlegroups .com>,
"Chung Leong" <ch***********@hotmail.comwrote:
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.

--
Philip
http://NikitaTheSpider.com/
Whole-site HTML validation, link checking and more
Jul 19 '06 #19

P: n/a

ab**********@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?
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

Jul 19 '06 #20

P: n/a
Nikita the Spider wrote:
In article <11**********************@h48g2000cwc.googlegroups .com>,
"Chung Leong" <ch***********@hotmail.comwrote:
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.
That's the whole point. This isn't a pointless debate like Linux vs.
Windows or Coke vs. Pepsi. People choose what OS they use. People
choose what they drink. Don't like Coke? --don't buy it. No one is
obliged to follow the Coca Company's advise. The W3C on the other hand,
as a quasi-official body, enjoys a certain aura of authority. Keeping
quiet about its decisions means implicit acquiescence.

Jul 20 '06 #21

P: n/a
Chung Leong wrote:
Nikita the Spider wrote:
>>In article <11**********************@h48g2000cwc.googlegroups .com>,
"Chung Leong" <ch***********@hotmail.comwrote:

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


That's the whole point. This isn't a pointless debate like Linux vs.
Windows or Coke vs. Pepsi. People choose what OS they use. People
choose what they drink. Don't like Coke? --don't buy it. No one is
obliged to follow the Coca Company's advise. The W3C on the other hand,
as a quasi-official body, enjoys a certain aura of authority. Keeping
quiet about its decisions means implicit acquiescence.
Chung,

OTOH, joining them and adding your own input means you may influence
their decisions.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 20 '06 #22

P: n/a
Rik
Jerry Stuckle wrote:
Chung Leong wrote:
>That's the whole point. This isn't a pointless debate like Linux vs.
Windows or Coke vs. Pepsi. People choose what OS they use. People
choose what they drink. Don't like Coke? --don't buy it. No one is
obliged to follow the Coca Company's advise. The W3C on the other
hand, as a quasi-official body, enjoys a certain aura of authority.
Keeping quiet about its decisions means implicit acquiescence.
OTOH, joining them and adding your own input means you may influence
their decisions.
That's true. Inluence is everything, even at W3C. They're thinking about the
pratical implications though.

Normally (not always) they're unbiased decisions. Which is a Good Thing.

Grtz,
--
Rik Wasmus
Jul 20 '06 #23

P: n/a
william.clarke wrote:
Read the W3C tutorials... http://www.w3schools.com/xhtml/xhtml_dtd.asp
don't think w3schools is affiliated with W3C.

http://www.google.com/search?q=site:w3c.org%20w3schools

--
Jock

Jul 20 '06 #24

P: n/a
What can html 4.01 do that xhtml can't?

As the spec [link: ] says, "[XHTML is ]a reformulation of HTML 4 as an
XML 1.0 application"

If i had to pick one to go with, i'd chose XHTML (Transitional,
personally, at this time...)

I'd rather be working with the better technology and have to deal with
'the browser issue' than push HTML 4.01 to the bitter end of its
usefulness/abilities.

C

Geoff Berrow wrote:
Message-ID: <11**********************@h48g2000cwc.googlegroups .comfrom
cwdjrxyz contained the following:
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.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 21 '06 #25

P: n/a
Colin wrote:
What can html 4.01 do that xhtml can't?

As the spec [link: ] says, "[XHTML is ]a reformulation of HTML 4 as an
XML 1.0 application"
Sort and sweet, work for MS IE.

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Jul 21 '06 #26

P: n/a
In article <11*********************@s13g2000cwa.googlegroups. com>,
"Colin" <co*******@gmail.comwrote:
What can html 4.01 do that xhtml can't?
Be served with the correct content-type to the world's most popular
browser.

--
Philip
http://NikitaTheSpider.com/
Whole-site HTML validation, link checking and more
Jul 21 '06 #27

P: n/a
Colin:
What can html 4.01 do that xhtml can't?
nothing, since neither (instances of) html4.01 nor xhtml *do* anything.

scnr.

another question, heading back in a more PHP/server-side direction:
why one or the other?

--
Jock

Jul 21 '06 #28

P: n/a
Colin wrote:
What can html 4.01 do that xhtml can't?

As the spec [link: ] says, "[XHTML is ]a reformulation of HTML 4 as an
XML 1.0 application"
Read aloud and repeat:

"[XHTML is] a reformulation of HTML 4 as an XML 1.0 application"

Louise

Jul 22 '06 #29

P: n/a
In article <N5*****************@news-server.bigpond.net.au>,
boclair <bo*****@bigpond.net.auwrote:
Read aloud and repeat:

"[XHTML is] a reformulation of HTML 4 as an XML 1.0 application"
At school, when we would go up and have our Latin exercises
assessed, if a student got something wrong, it was very often
cause for the teacher to sing song "The object is in the
accusative case..." and he expected and got the whole class to
join in... This was in the days before Dennis Potter and his BBC
TV series...

--
dorayme
Jul 22 '06 #30

P: n/a
Message-ID: <11*********************@s13g2000cwa.googlegroups. comfrom
Colin contained the following:
>If i had to pick one to go with, i'd chose XHTML (Transitional,
personally, at this time...)

I'd rather be working with the better technology and have to deal with
'the browser issue' than push HTML 4.01 to the bitter end of its
usefulness/abilities.

Better technology? XHTML transitional?

I think you are way off track here.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 22 '06 #31

This discussion thread is closed

Replies have been disabled for this discussion.