[nycphp-talk] Can code be executed in a heredoc?
Dan Cech
dcech at phpwerx.net
Wed Feb 18 00:27:46 EST 2004
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.
Personally I prefer to use either a string concatenation or a sprintf
method rather than embedding variables in double quoted strings in php,
as to my mind it makes it much more apparent where the variables are.
For the example above, compare:
$link = 'http://www.nyphp.org';
echo "<a href=\"$link\">Link Test</a>";
echo '<a href="'. $link .'">Link Test</a>';
printf ('<a href="%s">Link Test</a>', $link);
Usually I use the second syntax, occasionally the third (especially if I
were doing a loop), and almost never the first.
> 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.
Dan
More information about the talk
mailing list