W3C home > Mailing lists > Public > public-html@w3.org > July 2009

Re: PHP code only allowed in XHTML 5?

From: Thomas Broyer <t.broyer@ltgt.net>
Date: Thu, 23 Jul 2009 10:23:30 +0200
Message-ID: <a9699fd20907230123s3c0be171n2bc8a8317f139ccb@mail.gmail.com>
To: Leif Halvard Silli <lhs@malform.no>
Cc: HTMLWG <public-html@w3.org>
On Wed, Jul 22, 2009 at 7:50 PM, Leif Halvard Silli wrote:
> Thomas Broyer On 09-07-22 15.56:
>> If you're using PHP in an HTML document, you're likely to output HTML
>> markup (elements, attributes; not just attribute values) and therefore
>> have issues with validation before PHP processing (">" from HTML
>> markup within PHP strings being seen as the end of the "bogus
>> comment", "<?php" found within start tags)
> Again, this depend on the coding style. This is allowed in HTML 4 and in
> <table>
> <tr><td>content
> <?php code to insert more rows ?>
> </table>

Assuming you closed the </td> and </tr>, yes, but only if "code to
insert more rows" doesn't include a ">" (which would end the PI in
HTML 4).
In practice, it is likely that it will (include ">").

> Making PHP pages that are valid before execution is a choice of the author
> or the authoring tool.

If the author has to know that:
 - he must not use ">" (i.e. use \x3E instead) to be valid HTML 4 (and
to comply with how Firefox and Opera will parse the doc [1])
 - he must use paired quotes to comply with how IE will parse the doc [1]
 - he should not output HTML that would change the way the HTML is
parsed and alter its validity (i.e. <?php if ($foo) { echo
"<select\x3E"; } else { echo "<select multiple\x3E"; }
 - he must pay attention to the quote characters he uses in his PHP
code when placed within an HTML attribute value (e.g. value="<?php
echo "$foo $bar"; ?>" is invalid HTML)
 - he must not use "--" in his PHP code when placed within an HTML
comment (could be "--" in a string, or the decrement operator)
 - and if he also wants his document to be valid HTML *and* valid
XHTML (or at least well-formed XML), he must not use PHP within start
tags (neither in the tag itself or within attribute values)

If he does know all these things, cannot it just ignore any
warning/error regarding "<?" being invalid HTML5 ?

(I said "author" above, and not "authoring tool", because I can hardly
imagine a tool that would do any/all of this without the author being

[1] You could tell me that he won't open the page in a browser without
first processing the PHP code; but then what would be the point of
arguing that UAs do support the <? > syntax?

Thomas Broyer
Received on Thursday, 23 July 2009 08:24:10 UTC

This archive was generated by hypermail 2.4.0 : Saturday, 9 October 2021 18:44:51 UTC