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

Re: PHP code only allowed in XHTML 5?

From: Lachlan Hunt <lachlan.hunt@lachy.id.au>
Date: Thu, 23 Jul 2009 10:17:37 +0200
Message-ID: <4A681CA1.1040102@lachy.id.au>
To: Leif Halvard Silli <lhs@malform.no>
Cc: HTML WG <public-html@w3.org>
Leif Halvard Silli wrote:
> Anne van Kesteren On 09-07-22 12.53:
>> and also does not work in common PHP scenarios
>> such as
>>
>> <div<?php if($foo) { echo " class='bar'"; }?>>
>
> But since we are talking HTML and not XHTML, you could use
>
> <div class=' <?php if($foo) { echo " bar"; }?>' >
>
> and be valid.

That doesn't work for boolean attributes, where you have to do this:

<input type="checkbox"<?php echo $disabled ? ' disabled' : ""; ?>>

The only way to achieve the same result, while still technically being 
well-formed XML or SGML is to do this:

<?php if ($disabled) { ?>
   <input type="checkbox" disabled="disabled" />
<?php } else { ?>
   <input type="checkbox" />
<?php } ?>

But that doesn't really scale well when you have multiple attributes, 
each requiring their own if statement.

-- 
Lachlan Hunt - Opera Software
http://lachy.id.au/
http://www.opera.com/
Received on Thursday, 23 July 2009 08:18:17 UTC

This archive was generated by hypermail 2.3.1 : Thursday, 29 October 2015 10:15:48 UTC