If PHP programmers are creating a link from variables often you can see the following code:
echo '<a href="' . $link . '" id="' . $id .'" class="' . $class . '">' . $linktext . '</a>';
?> <a href="<?php echo $link; ?>" id="<?php echo $id; ?>" class="<?php echo $class; ?>"><?php echo $linktext; ?></a> <?php
echo "<a href=\"$link\" id=\"$id\" class=\"$class\">$linktext</a>";
Apart from the personal preferences of the programmer all these snippets have one thing in common: they are hard to read. “Sure!”, you will say, “attributes in HTML have to be enclosed in double quotes and in PHP I have to use one of the above methods.” Are you sure? Do attributes really have to be enclosed in double quotes? The simple answer is: No!
Let’s take a look at the specification:
[…] By default, SGML requires that all attribute values be delimited using either double quotation marks (ASCII decimal 34) or single quotation marks (ASCII decimal 39). Single quote marks can be included within the attribute value when the value is delimited by double quote marks, and vice versa. […]
Double or single quotation marks. That will make things much easier:
echo "<a href='$link' id='$id' class='$class'>$linktext</a>";
As you see the code is much easier to read and that simply happened because you read the specs!