NYCPHP Meetup

NYPHP.org

[nycphp-talk] Can code be executed in a heredoc?

Dan Cech dcech at phpwerx.net
Wed Feb 18 08:49:49 EST 2004


Adam Maccabee Trachtenberg wrote:
> On Wed, 18 Feb 2004, Dan Cech wrote:
> 
>>Adam Maccabee Trachtenberg wrote:
>>
>>>On Tue, 17 Feb 2004, Daniel J Cain Jr. wrote:
>>>
>>>>Is it bad form to use the format below?  Instead of escaping all double
>>>>quotes to use single quotes for the tag attributes.
>>>>
>>>>echo "<a href='http://www.nyphp.org'>Link Test</a>";
>>>
>>>While that is technically legal HTML, until someone can prove it to me
>>>otherwise, I've never trusted that some stupid browser won't barf on
>>>it.
>>
>>The term 'technically legal HTML' is about as broad as you can get, but
>>yes it is more or less acceptable.  However the convention is to use
>>double-quotes to enclose attribute values in html/xhtml/xml.
> 
> Define "more or less acceptable."
> 
> All I'm saying that the specification allows it (hell, it even allows
> you to omit quotation marks of any sort in some cases), but that I
> don't trust that UAs correctly implement the spec.
> 
> http://www.w3.org/TR/html401/intro/sgmltut.html#h-3.2.2
> 
> Whether the convention is to use double quotes or single quotes is a
> different issue.

Indeed, you are correct in that specification allows it, my point was 
that depending on whether you interpret 'HTML' as HTML 3.2, 4.0, 4.01, 
XHTML 1.0, or any of the flavours thereof, what is 'technically legal' 
can vary quite widely.

What I meant by 'more or less acceptable' is that while the (HTML 4.01) 
specs do allow it, but the convention seems to be to use double-quotes, 
and as you pointed out this has the greatest chance of being interpreted 
correctly by the majority of browsers.

The other thing I wanted to mention was that whatever style of quotes 
are used, they should be used consistently.  Mixing different quoting 
styles in your documents isn't as nasty as mixing upper and lower-case 
tags in HTML, but it's close.

>>>For XML, I'm willing to do this, since I usually have control over the
>>>parser and I'm willing to trust (for some reason) that XML parsers get
>>>this right.
>>
>>I can't really comment on how xml parsers would handle this, the w3c
>>specs (at first glance) don't seem to specify the exact quoting method
>>which is 'valid', but here again the generally accepted norm seems to be
>>double-quotes.
> 
> Huh? It's pretty clear (or as clear as W3C specs get):
> 
> http://www.w3.org/TR/2004/REC-xml-20040204/
> 
> Literal data is any quoted string not containing the quotation mark
> used as a delimiter for that string. Literals are used for specifying
> the content of internal entities (EntityValue), the values of
> attributes (AttValue), and external identifiers (SystemLiteral). Note
> that a SystemLiteral can be parsed without scanning for markup.
> 
> Literals
> [9]   EntityValue   ::=   '"' ([^%&"] | PEReference | Reference)* '"'
>                           |  "'" ([^%&'] | PEReference | Reference)* "'"
> [10]  AttValue      ::=   '"' ([^<&"] | Reference)* '"'
>                           |  "'" ([^<&'] | Reference)* "'"
> [11]  SystemLiteral ::=   ('"' [^"]* '"') | ("'" [^']* "'")
> [12]  PubidLiteral  ::=   '"' PubidChar* '"'
>                           | "'" (PubidChar - "'")* "'"
> [13]  PubidChar   ::=   #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
> 
> Like I said, if you squint you can see that you can use single or
> double quotes.

Thanks for digging up the specs, I made an attempt but it was too late 
at night for me.

Dan





More information about the talk mailing list