I want to do something crazy and stupid with PHP (19)

1 Name: #!/usr/bin/anonymous : 2007-02-08 17:01 ID:zvVFiOKj

So, hypothetically speaking, I have a user, some guy on the internet, who goes to my website and requests mysite.com/resource; it points to a PHP script that follows this outline:

1) Tests whether or not the user agent can understand application/xhtml+xml.

2) uses XML functions to load resource.xml.

3) If the user agent can do as asked in #1, outputs a valid XHTML document (including MIME type, trailing slashes for empty tags, CDATA blocks, and so on).

4) If the user agent cannot do as asked in #1, outputs a strictly valid HTML document, where trailing slashes in empty tags are interpreted as minor errors on the author's part, but shorttags are permissible if used correctly.

So anyway, I could do this using a bunch of custom functions, but I was wondering if there were any shortcuts or library functions that would allow me to more quickly output strictly valid text. Or possibly something like server-side parsing of XSLT?

2 Name: #!/usr/bin/anonymous : 2007-02-08 22:17 ID:Heaven

Why would you want to output strictly valid HTML in the first place? Any browser is going to treat it with great suspicion anyway, and won't care if it's strictly valid or not, and serving up valid XHTML as text/html works perfectly, except for giving obsessive nerds a headache.

3 Name: #!/usr/bin/anonymous : 2007-02-08 22:27 ID:Heaven

>>2
When you say "works perfectly," are you referring to the part where the document is parsed in Quirks Mode and never sees the browser's XML engine?

And IE7 obeys the W3C's box model when in Standards Compliance Mode, but uses IE6's buggy box model when in Quirks Mode.

4 Name: #!/usr/bin/anonymous : 2007-02-09 02:46 ID:Heaven

>>3

Obviously, since it would make no sense to send HTML through an XML engine. I think you missed the point of the discussion.

5 Name: #!/usr/bin/anonymous : 2007-02-09 05:32 ID:Heaven

>>4

I think you missed the point of content negotiation.

6 Name: #!/usr/bin/anonymous : 2007-02-10 06:13 ID:mWYU05Xp

I think >>1 is getting too carried away with being pedantic about web standards. SGML parsers are completely competent at parsing XHTML data, there is no reason to waste your time with this excess of content negotiation. Just do your page up in valid XHTML, and send the correct MIME type if the browser can accept it. Problem solved.

7 Name: #!/usr/bin/anonymous : 2007-02-10 19:45 ID:/iucJ0UB

>>6

<body>
<script src="some_file.js" type="text/javascript"/>
<p>works in XHTML, but not in HTML!</p>
</body>

8 Name: #!/usr/bin/anonymous : 2007-02-11 02:30 ID:Heaven

>>5

Maybe you are addressing what I said in >>2, because what I said in >>4 was "this thread is about content negotiation"?

And I get the point exactly, I'm just saying that it's wasted effort for zero payoff in this case.

9 Name: #!/usr/bin/anonymous : 2007-02-11 05:36 ID:mWYU05Xp

>>7
That's all fine and dandy, but the only people I've seen use <script> tags inside the body and not head are people INJECTING MALICIOUS CODE. So, by all means, go use your XHTML which does that.

10 Name: #!/usr/bin/anonymous : 2007-02-11 12:00 ID:tkPdneWt

I'm not sure about UA MIME type detection, but this might be what you're looking for as far as XSLT goes:

http://au3.php.net/manual/en/ref.xsl.php

11 Name: #!/usr/bin/anonymous : 2007-02-12 17:11 ID:Heaven

>>9

He's referring to the use of 'script' as an empty element, you can put the tags inside the body in HTML as well, Google and some WYSIWYG editors do it.

12 Name: #!/usr/bin/anonymous : 2007-02-12 19:44 ID:Heaven

>>9
unless you want the body to be there when the script runs...
i've had problems with the body element not existing yet when i try to do document.body.onload=init; in the head instead of the body.

13 Name: #!/usr/bin/anonymous : 2007-02-13 09:53 ID:Heaven

>>7
sometimes you want a script to run as soon as the dom tree loads, and not have it wait around for all the images/flash/ads/etc to finish loading too (which might be slow or whatever). or you want to do something more complex than can easily be achieved in an onload event. solution? chuck it in a script tag between the closing body and html tags.

14 Name: #!/usr/bin/anonymous : 2007-05-18 10:36 ID:AbhB5cAs

>>9

Google Analytics requires you to put the urchin tracker include inside the body element for the script to function completely.

15 Name: #!/usr/bin/anonymous : 2007-05-19 04:38 ID:Heaven

ITT we respond to trolls who got bored and left 3 months ago

16 Post deleted by moderator.

17 Name: #!/usr/bin/anonymous : 2007-05-20 14:53 ID:Heaven

>>16
Best post in this thread.

18 Name: sage : 2007-05-21 09:21 ID:AbhB5cAs

You disappoint me code/

19 Name: #!/usr/bin/anonymous : 2007-05-21 11:02 ID:Heaven

You disappoint me, sage

This thread has been closed. You cannot post in this thread any longer.