Jump to content

Can you mix XHTML with PHP


HGeneAnthony

Recommended Posts

I like the concept of XHTML but I was wondering is it possible to use XHTML markup inside of a PHP page and is it possible to use it with Internet Explorer?  I tried creating an XHTML document one time and XHTML only worked with Firefox.  I was able to use the xml like tags using PHP pages under Firefox but they were ignored in Internet Explorer.  Does anyone have any suggestions how I can used xhtml like pages with IE?  Also I heard using the xhtml declaration at the top of a page can make it load quicker because it assumes the tags are good and it doesn't try to fix broken tags it just assumes they're good.  Is this also true?

Link to comment
Share on other sites

First, I'd just like to say that XHTML is very simply "HTML that follows the XML standards." You can also translate it to mean "XML with a limited, pre-defined set of tags."

 

I was wondering is it possible to use XHTML markup inside of a PHP page and is it possible to use it with Internet Explorer?

 

 

Yes, you can use XHTML markup in a PHP page. You can use any kind of markup you want in a PHP page, as long as the browser on the other end will interpret it.

 

I tried creating an XHTML document one time and XHTML only worked with Firefox.  I was able to use the xml like tags using PHP pages under Firefox but they were ignored in Internet Explorer.  Does anyone have any suggestions how I can used xhtml like pages with IE?

 

Internet Explorer can interpret XHTML, so the only thing I can think of is that you weren't creating the document correctly. (The computer is very rarely the one at fault.)

 

Also I heard using the xhtml declaration at the top of a page can make it load quicker because it assumes the tags are good and it doesn't try to fix broken tags it just assumes they're good.  Is this also true?

 

The XHTML doctype at the top of the page doesn't do anything but inform the browser what the format of the page is, so the browser doesn't have to guess. I don't think it would affect loading time, although it will affect the actual rendering. Without a proper doctype, the browser will switch into "quirks mode", where it will interpret the website however it wants to. If you make sure to use a proper doctype, the browser knows the exact rules it has to follow.

Link to comment
Share on other sites

On XHTML in IE, as far as I know with 6 and 7 if you try to name your page xhtml it won't load it will give you a download page instead.  As far as my code being broken if I'm correct xhtml specifies all lower case tags, all tags must be closed, all attributes need to be in parenthesis either single or double, and all attributes need a value.  You should also not use any tags that affect layout like <b> or <i> or <i> and should be replaced with descriptive tags like strong.  You also shouldn't use <br>.  Now I thought xhtml has a preset amount of tags and you can add your own tags like xml.  With a stylesheet you can then specify rules for these tags.  I would assume this would be allowed:

 

<html>
<head>

<style type="text/css">
name {
  color: red;
}
</style>


<title></title></head>
<body>
<div>My name is <name> Gene</name></div>
</body>
</html>

 

In Firefox Gene would be in red color in IE it doesn't do anything

 

I didn't expect it to cut down on the download time but I thought since it was taught to render the page using strict rules it would treat the page as complete and not try to fix it which I believe would increase actual rendering performance.

Link to comment
Share on other sites

To style straight XML in your layouts, you need to either use XSL, or the XML CSS declaration.

 

And the downloading-and-not-loading is a result of the web server not sending the correct headers with the files. This can be solved (in Apache) with a simple section in httpd.conf, the vhost, or the per-dir configuration files:

 

<FilesMatch "\.(xhtml|asdf|qwer)">
ForceType text/html
</FilesMatch>

 

And, with that simple directive in .htaccess, we get the following extensions interpreted as HTML: .xhtml, .asdf, and .qwer.

Link to comment
Share on other sites

So there's no problem using xhtml in a php page with IE?  Does this apply to 6 as well.  I decided I'm honoring browsers going back to ie6 but no farther.  Too restrictive limiting my pages for people still using IE 5.5, etc.

 

No problems at all.  Theres no need for the xhtml extension though, as long as you have the correct doc type definition in place and validate your pages.

Link to comment
Share on other sites

One more question though I didn't see this listed on tutorial sites but can you use custom tags/elements and attributes with xhtml (like xml) or do you need to stick with the standard xhtml tags?  Also is it possible to use xhtml files with css and highlight custom tags or do I needs xslt?  In Forefox it doesn't seem to matter but IE's a different story.

Link to comment
Share on other sites

  • 2 weeks later...

This needs to be cleared up here, ASAP. Nothing has been more damaging to web standards understanding and proper markup syntax than the whole "xhtml is the future html wave" that started @ 5years ago.

 

XHTML 1.0 transitional/strict was created to parse XML using the mime type (media type) of "application/XHTML-XML".

 

However, the w3c stated it "MAY" be used as HTML when using the mime type of text/html (PROVIDED IT CAN ALSO BE SERVED USING "application/XHTML-XML"). I think this was a stroke-job to appease Microsoft because IE 5.5 didn't know what the hell the mime type (media type) of "application/XHTML-XML" was, and they were already in beta testing for IE 6 (which was also clueless).

 

Meanwhile, everybody JUMPED all over the "MAY BE SERVED AS TEXT/HTML" provision and started churning out book after book on xhtml being the friggin' sliced bread of web code ... um, of course leaving out that whole "techie/annoying thing" about XML and application/xhtml-xml.

 

So everyone who started to learn web design was spoon fed xhtml instead of HTML. They even grouped it together with css as if xhtml/css MEANT table-less layout and HTML was table based. AND they made it seem as if XHTML was the conservative, strict, law abiding grandson of that liberal, hippy, smelly HTML - who ran around naked, with no morals, rules or structure.

 

But guess what?

 

When NOT used to actually parse XML, and served as "text/html" all XHTML does is become converted by the browser to HTML (with strange closing tags and somewhat stricter rules than the optional rules of HTML).

 

In fact, it turns out that HTML is just as happy with the well formedness, and struture rules of xhtml. All Lowercase? fine.  Closing tags? No problem - except for those pesky single tag slashes like for img, br, meta.

 

AND, HTML 4.01 Strict is tougher on validation standards than xhtml 1.0.

 

When IE 7 also didn't support xhtml as XML, the w3c said "enough"!

 

XHTML 2.0 will not be allowed to be served as "text/html".  Which means it will not work at all in any IE up to 7.0 - and most likely 8.0.

 

XHTML 1.1 strict served as text/html is wonky in IE.

 

So why use xhtml at all? You can use the same basic format of markup formatting as you do in xhtml (except for single closing tags).

 

As a matter of fact, HTML 4.01 strict is absolutely unforgiving of anything that doesn't conform to the HTML 4.01 specification. It is even stricter than xhtml 1.0!

 

When I look at a web page that validates and see HTML 4.01 strict as the doctype, I KNOW that site was done by a true professional who knows better AND is serious.

 

When I see XHTML 1.0 transitional served as text/html, I know the person is just a beginner or they are  copying code from a book or template.

 

When I see XHTML 1.0 strict served as text/html AND it doesn't validate, I know the site was done by someone who knows enough to not understand it.

 

When I see XHTML 1.1 strict served as text/html, I know the site was done by someone who just doesn't get it at all.

 

And I cringe whenever I see someone who wants to start using xhtml. I know they will not understand when I tell them they shouldn't. Because I didn't two years ago when I started using xhtml. And I know they have a lot of work ahead of them when they finally DO understand and have all those pages to convert to HTML 4.01 strict, like I am in the process of - because once you think you are rules tough because you used xhtml, you will find out what rules tough really is when you try to convert them to html 4.01 strict.

 

 

Link to comment
Share on other sites

Bla bla bla... as long as W3C says it's okay it's okay.

 

LOL! I LOVE this issue because some people always roll out that catch all response without understanding the issue itself. they just don't want to face the xhtml dead-end.

 

Sure it's "okay" ... so are "transititional doctypes" - even though the actual code has nothing to do with the version specification and proves the coder is either lazy or unprofessional.

 

The whole reason I even stand on this soapbox every now and then is that I already see tons of "why doesn't my page work?" in the forums, only to see because people are using xhtml 1.0 strict, but coding for html 3, and now I see them using xhtml 1.1 served as text/html and the pages aren't working at all - or blowing up quite nicely.

 

And W3C's validator doesn't complain about XHTML 1.0 served as text/html.

 

Yup ... because like I said, it "MAY BE" served as such - "only to accommodate non-modern browsers".

 

Here is the exact chart from the w3c showing that only xhtml 1.0 may be served as (html), which proves xhtml to be a dead end as a replacement for HTML 4.01 strict, since only xhtml 1.0 will ever be permitted to be served as html:

 

http://www.w3.org/TR/2002/NOTE-xhtml-media-types-20020801/#summary

 

What it basically shows is that XHTML 1.1 SHOULD NOT and XHTML 2.0 MAY NOT so, you will forever be using xhtml 1.0 as the only xhtml (as html) for your website, forever. Period.

 

Also, check out what mime type w3.org is served as, yeah, text/html and it's DOCTYPE is XHTML 1.0 Strict.

 

Yeah ... which is what started the whole mess in the first place - the home page structure was written in 2004. They never do get around to updating, even their content ... the w3c tutorials for html are no longer even 4.01 valid.

 

AND notice I didn't mention anything in my post about "valid" xhtml 1.0 strict"? What I said was:

 

When I see XHTML 1.0 strict served as text/html AND it doesn't validate, I know the site was done by someone who knows enough to not understand it.

 

If anyone is going to start using xhtml. They better know what they are getting into.

 

 

Link to comment
Share on other sites

What it basically shows is that XHTML 1.1 SHOULD NOT and XHTML 2.0 MAY NOT so, you will forever be using xhtml 1.0 as the only xhtml (as html) for your website, forever. Period.

According to RFC2119 "SHOULD NOT" does not mean it's not allowed so you can serve XHTML 1.1 as text/html. Besides, you can just send another content-type header, so I don't see any problem.

 

Also, where do you see that HTML 4.01 Strict is "more strict" than XHTML 1.0 Strict?

XHTML is a family of current and future document types and modules that reproduce' date=' subset, and extend HTML 4.[/quote']

Seems to me like they're equally strict...

 

It's pretty easy to come and claim all sorts of things without proofs. So let's see them.

Link to comment
Share on other sites

When the contents of an XHTML document are served as XML then it becomes extremely unforgiving. The slightest parse error will result in the whole page not being served. You can serve the contents of an XHTML 1.0 doc as text/html but it should also work when served as xml...but most websites using xhtml doctypes will simply die when served as XML.

 

There is really no point using xhtml when html 4.01 strict will do exactly the same job and not kill your page if you have a small coding error, or some user-generated content that is not 100% valid, or an external link that your CMS didn't fix the ampersands in, etc.

 

But since you are using an xhtml doctype to take advantage of xml you are going to be limited in what browsers will display your pages becauase...

 

Internet Explorer can interpret XHTML, so the only thing I can think of is that you weren't creating the document correctly. (The computer is very rarely the one at fault.)

 

IE won't accept an XHTML document being served as "application/xhtml-xml". It's that simple.

 

Bla bla bla... as long as W3C says it's okay it's okay. And W3C's validator doesn't complain about XHTML 1.0 served as text/html. Also, check out what mime type w3.org is served as, yeah, text/html and it's DOCTYPE is XHTML 1.0 Strict.

 

The W3C says it's ok, with conditions. The whole point is that the contents of an XHTML 1.0 doc can be served as text/html but should also work when served as application/xhtml-xml! The w3.org website has an xml declaration.

 

The w3.org are not infallible either. Some of their definitions in their documentation are simply wrong - famously the distinction between an acronym and an abbreviation. Given the current situation with html5 and xhtml2, I doubt their next site build will be using xhtml, and it certainly wouldn't be done by serving xhtml 1.1 as text/html.

 

The only time I still use xhtml doctypes served as html/text is for professional work, because clients look for agencies that use xhtml, some javascripts that they want to use were built for xhtml doctypes (who knows why), and a lot of CMS now pump out xhtml tags! The reality is that html 5, not any form of xhtml, is going to be the next standard.

Link to comment
Share on other sites

Also, where do you see that HTML 4.01 Strict is "more strict" than XHTML 1.0 Strict?

Quote from: http://www.w3.org/TR/xhtml1/#xhtml

XHTML is a family of current and future document types and modules that reproduce, subset, and extend HTML 4.

Seems to me like they're equally strict...

 

It's pretty easy to come and claim all sorts of things without proofs. So let's see them.

 

This debate always either gets heated from both sides, or one side begins getting nasty and sarcastic (forcing the HTML side into responding the same).

 

So I'm not going there.

 

Just let me point out that I never said "HTML 4.01 Strict is 'more strict' than XHTML 1.0 Strict".

 

And, yes, I admit I was intentionally being misleading when I left out XHTML 1.0 Strict or Transitional. Because the whole point I am trying to make is that people are led to believe that just because they use XHTML , it is automatically more strict than HTML.

 

When the reality is that when served as text/html, XHTML, in essence, IS HTML 4.01 with the "optional" features of HTML turned off (and the closing single tags added). There is virtually no difference in content display or functionality between equal doctypes of XHTML 1.0 and HTML 4.01 (transitional and strict respectively).

According to RFC2119 "SHOULD NOT" does not mean it's not allowed so you can serve XHTML 1.1 as text/html.

 

Come on ... you know better than that. Ignoring the specification of SHOULD NOT will send the document into quirks mode and there is no telling WHAT it will do with respect to cross browser - cross platform compatibility (although IE will love it).

 

Besides, you can just send another content-type header, so I don't see any problem.

 

????!!! Why would you possibly do THAT? What purpose does it serve? If you send another media type, it will not work at all in IE. Or if you use a browser sniffer to send the correct media type to modern browsers and text/html to IE, it will be in quirks mode in IE because XHTML 1.1 "SHOULD NOT" be served as text/html ... see the problem?

 

Well, I suppose if you are using a browser sniffer you could also tell IE to use XHTML 1.0 and text/html.

 

This way you actually do stay within the specifications and your pages will validate.

 

... or you can just make it html 4.01 Strict in the first place.

 

I'm done.  And here is what I recommend to HGeneAnthony, who started this thread because he likes the concept of XHTML.

 

Those of us who also liked the XHTML concept a few years ago realized that we could actually adhere to the same exact concept of rigid rules of structure, coding and content ... so we apply that concept when coding, but use the HTML 4.01 Strict DOCTYPE.

 

And if you want to parse XML ... just parse it to HTML because IE will not display an XHTML document served as "application/xhtml-xml".

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.