Re: PHP code only allowed in XHTML 5?

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