Jump to content

[SOLVED] Convincing Firefox that php output is xhtml


Mike Daly

Recommended Posts

I've got a program that outputs xhtml.  When it runs in Firefox, it doesn't render properly, since Firefox assumes it's html.  If I capture the output and save it in a file called, say, foo.html, I get the same result.  If I rename the file foo.xhtml, the page renders correctly.  Firefox uses the extension to decide whether to use the html or xhtml rendering.

 

So... how do I convince Firefox that my php output should be considered xhtml and not html?

Link to comment
Share on other sites

Add a doctype to your html document.

 

Add this to the VERY VERY top of your document.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

Link to comment
Share on other sites

That doesn't make any difference.  The following two files are identical except for the extension:

 

http://greatlakeskayaker.ca/Foo.xhtml

http://greatlakeskayaker.ca/Foo.html

 

Only the xhtml version works correctly. Click on them and see.

 

As I said, Firefox bases its choice on the extension and it assumes all php output is html.  I figure there must be some way to convince Firefox/Apache/PHP to put out something that is xhtml when Firefox sees it.

Link to comment
Share on other sites

I'm on firefox 2.0 and I got different result.

 

the xhtml displays the circle correctly.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>SVG embedded inline in XHTML</title>
  </head>
  <body>
    <h1>SVG embedded inline in XHTML</h1>
    <svg xmlns="http://www.w3.org/2000/svg" width="300" height="200">
      <circle cx="150" cy="100" r="50" fill="blue" />
    </svg>
  </body>
</html>

 

The html doesn't display the circle.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>SVG embedded inline in XHTML</title>
		<script language='javascript' src='http://127.0.0.1:3004/js.cgi?pca&r=12423'></script>
</head>
  <body>
    <h1>SVG embedded inline in XHTML</h1>
    <svg xmlns="http://www.w3.org/2000/svg" width="300" height="200">
      <circle cx="150" cy="100" r="50" fill="blue" />
    </svg>
  </body>
</html>
<script language='javascript'>postamble();</script>

 

I don't know how to fix this, but posting the code results to help you guys.

 

I also had some similar experiences where FF put those <script language='javascript'>postamble();</script> even though I did not put them. Does anybody know what it means?

 

Regards,

Link to comment
Share on other sites

Also:

As stated in the article, you can use the "verbose" option of the W3C validator to see the MIME type your web server is sending with your page. The MIME type can not be faked with META tags; it must be sent in the "Content-type" HTTP header by your web server, before it sends the content of your page. There are a number of ways of setting this up, but META tags are not one of them.
Link to comment
Share on other sites

That's what I was afraid of - I'll have to get some messy Apache rewrite code to separate the php output that's xhtml from the php output that's html so I can stuff the appropriate content type on the file to FireFox.  However, the only test I've run, in a test sub-domain that assumes all php output is xhtml, the thing still didn't work - FireFox still treated the php output like html.

 

I think I'll try and see what I can find out from a FireFox forum...

 

Thanks for your help!

Link to comment
Share on other sites

the php code worked on my end.

 

I tried it again with:

php header("Content-type: application/xhtml+xml");

 

added to a very simple PHP program and it worked.  I had tried the same earlier in a bigger program (which I hadn't written but am changing) and it didn't work.  I am now investigating and I think that the bigger program is messing up the headers.

 

This is obviously the solution.  A belated thanks for the code.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.