serving xhtml with php

Discussion in 'HTML' started by abracad_1999@yahoo.com, Jul 19, 2006.

  1. 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?
     
    , Jul 19, 2006
    #1
    1. Advertising

  2. flamer Guest

    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.
     
    flamer , Jul 19, 2006
    #2
    1. Advertising

  3. Chung Leong Guest

    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 ... ?' . '>';
     
    Chung Leong, Jul 19, 2006
    #3
  4. Chung Leong Guest

    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.
     
    Chung Leong, Jul 19, 2006
    #4
  5. boclair Guest

    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
     
    boclair, Jul 19, 2006
    #5
  6. Rik Guest

    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
     
    Rik, Jul 19, 2006
    #6
  7. cwdjrxyz Guest

    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.
     
    cwdjrxyz, Jul 19, 2006
    #7
  8. Kimmo Laine Guest

    "cwdjrxyz" <> wrote in message
    news:...
    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()
     
    Kimmo Laine, Jul 19, 2006
    #8
  9. Noodle Guest

    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?
     
    Noodle, Jul 19, 2006
    #9
  10. Guest

    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, 2006
    #10
  11. cwdjrxyz Guest

    Kimmo Laine wrote:
    > "cwdjrxyz" <> wrote in message
    > news:...
    > 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.
    >
     
    cwdjrxyz, Jul 19, 2006
    #11
  12. Chung Leong Guest

    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."
     
    Chung Leong, Jul 19, 2006
    #12
  13. cwdjrxyz Guest

    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 :) .
     
    cwdjrxyz, Jul 19, 2006
    #13
  14. Geoff Berrow Guest

    Message-ID: <> from
    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/
     
    Geoff Berrow, Jul 19, 2006
    #14
  15. Chung Leong Guest

    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.
     
    Chung Leong, Jul 19, 2006
    #15
  16. cwdjrxyz Guest

    Geoff Berrow wrote:
    > Message-ID: <> from
    > 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.
     
    cwdjrxyz, Jul 19, 2006
    #16
  17. Geoff Berrow Guest

    Message-ID: <> from
    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/
     
    Geoff Berrow, Jul 19, 2006
    #17
  18. On 2006-07-19, Geoff Berrow wrote:
    > Message-ID: <> from
    > 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)
     
    Chris F.A. Johnson, Jul 19, 2006
    #18
  19. In article <>,
    "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."


    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
     
    Nikita the Spider, Jul 19, 2006
    #19
  20. 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
     
    william.clarke, Jul 19, 2006
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rajive Narain
    Replies:
    0
    Views:
    1,896
    Rajive Narain
    Sep 18, 2009
  2. -[ CaMeL ]- a55m0nk

    serving pages in ASP ala PHP

    -[ CaMeL ]- a55m0nk, Oct 25, 2003, in forum: ASP General
    Replies:
    3
    Views:
    189
    Ray at
    Oct 27, 2003
  3. Marc Heiler

    Webrick serving php pages?

    Marc Heiler, Jul 29, 2006, in forum: Ruby
    Replies:
    2
    Views:
    253
    Matt Todd
    Jul 29, 2006
  4. Replies:
    1
    Views:
    99
  5. -Lost
    Replies:
    7
    Views:
    172
    Randy Webb
    Jun 20, 2007
Loading...

Share This Page