Mike Daly Posted June 13, 2007 Share Posted June 13, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/55384-solved-convincing-firefox-that-php-output-is-xhtml/ Share on other sites More sharing options...
Nhoj Posted June 13, 2007 Share Posted June 13, 2007 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"> Quote Link to comment https://forums.phpfreaks.com/topic/55384-solved-convincing-firefox-that-php-output-is-xhtml/#findComment-273715 Share on other sites More sharing options...
Mike Daly Posted June 14, 2007 Author Share Posted June 14, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/55384-solved-convincing-firefox-that-php-output-is-xhtml/#findComment-274372 Share on other sites More sharing options...
sKunKbad Posted June 14, 2007 Share Posted June 14, 2007 I'm on Firefox 1.5 and both pages validate extactly the same. Quote Link to comment https://forums.phpfreaks.com/topic/55384-solved-convincing-firefox-that-php-output-is-xhtml/#findComment-274402 Share on other sites More sharing options...
mr_zhang Posted June 14, 2007 Share Posted June 14, 2007 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, Quote Link to comment https://forums.phpfreaks.com/topic/55384-solved-convincing-firefox-that-php-output-is-xhtml/#findComment-274423 Share on other sites More sharing options...
Mike Daly Posted June 14, 2007 Author Share Posted June 14, 2007 Interesting - I use FF 2.0.0.4 and no script has been added; both show the same code when "view page source" is used. Quote Link to comment https://forums.phpfreaks.com/topic/55384-solved-convincing-firefox-that-php-output-is-xhtml/#findComment-274621 Share on other sites More sharing options...
Mike Daly Posted June 14, 2007 Author Share Posted June 14, 2007 I'm on Firefox 1.5 and both pages validate extactly the same. Do you see the blue circle on both or just text? Quote Link to comment https://forums.phpfreaks.com/topic/55384-solved-convincing-firefox-that-php-output-is-xhtml/#findComment-274623 Share on other sites More sharing options...
Corona4456 Posted June 14, 2007 Share Posted June 14, 2007 <?php header("Content-type: application/xhtml+xml"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/55384-solved-convincing-firefox-that-php-output-is-xhtml/#findComment-274638 Share on other sites More sharing options...
Mike Daly Posted June 14, 2007 Author Share Posted June 14, 2007 Coincidently, as you were posting that, I added: <meta http-equiv="Content-Type" content="application/xhtml+xml" charset="utf-8"/> to the Foo.(x)html examples and nothing changed. Quote Link to comment https://forums.phpfreaks.com/topic/55384-solved-convincing-firefox-that-php-output-is-xhtml/#findComment-274642 Share on other sites More sharing options...
Corona4456 Posted June 14, 2007 Share Posted June 14, 2007 the php code worked on my end. Quote Link to comment https://forums.phpfreaks.com/topic/55384-solved-convincing-firefox-that-php-output-is-xhtml/#findComment-274651 Share on other sites More sharing options...
Corona4456 Posted June 14, 2007 Share Posted June 14, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/55384-solved-convincing-firefox-that-php-output-is-xhtml/#findComment-274674 Share on other sites More sharing options...
Mike Daly Posted June 14, 2007 Author Share Posted June 14, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/55384-solved-convincing-firefox-that-php-output-is-xhtml/#findComment-274994 Share on other sites More sharing options...
Mike Daly Posted June 19, 2007 Author Share Posted June 19, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/55384-solved-convincing-firefox-that-php-output-is-xhtml/#findComment-277297 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.