Jump to content

Quotes


knystrom18

Recommended Posts

Does it matter, or is there a difference between a single quote or double quotes around values in XHTML? If so, why? Something with parsing?Ex:

<input type='text' size='20' name='first_name'>

VS:

<input type="text" size="20" name="first_name">

Link to comment
Share on other sites

Good question.According to the specification - http://www.w3.org/TR/2002/REC-xhtml1-20020801/#h-4.4, attributes must be quoted, but it doesn't state whether single- or double-quotes are required.To test the theory I validated the following code at W3C.org:

<?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><title>Quote test</title><link rel="stylesheet" type="text/css" href="css/style.css" /></head><body><h1>Quote Test</h1><p>This is a test to see if attributes enclosed in single quotes validate.</p><p id='pid'>Single quote id attribute</p></body></html>

And it validates.I like to use double-quotes, because if the code is echoed out of PHP, the tag can be enclosed with single quotes in PHP - which are processed faster than double-quoted strings.http://www.php.net/manual/en/language.type...g.syntax.doubleThis link has a demonstration of the impact of quote choice on execution time: http://wirehopper.com/timetest.phpIn the results, you can see that the single-quoted version is significantly faster than double-quoted.

preg_replace: 0.000126preg_replace: 0.000009 (single quotes)
Link to comment
Share on other sites

Good answer.So it doesn't really matter; it all validates. The only factor is speed, which I guess depending on the size and content of the site, could matter quite a bit.Thanks.- K

Link to comment
Share on other sites

  • 4 weeks later...

Wow, didn't know that you could use single qoutes in XHTML. And I didn't know that single qoutes were faster. Thanks for the info.

Link to comment
Share on other sites

Using single quotes are faster, in PHP, because variables aren't evaluated inside. However, you can always escape your quotes.Note that another reason why you might need to choose one quotation character over the other in XHTML is because of the value of an attribute:

<input value='Some "quoted" value' />

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...