To & or &, that is the question..

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
Kev
Forum Newbie
Posts: 21
Joined: Tue Aug 25, 2009 9:11 pm

To & or &, that is the question..

Post by Kev »

When writing XHTML, specifically creating anchor tags for links, should you use html entities for characters in URL's like &?

For instance... if I'm writing XHTML, which is correct?

Code: Select all

<a href="http://www.example.com/index.php?a=2&z=9">Link</a>
or

Code: Select all

<a href="http://www.example.com/index.php?a=2&z=9">Link</a>
I never could quite figure this out. Thanks!
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: To & or &amp;, that is the question..

Post by alex.barylski »

Run your code through a validator and find out? :P

p.s-It's the latter form I do believe.

Cheers,
Alex
User avatar
Kev
Forum Newbie
Posts: 21
Joined: Tue Aug 25, 2009 9:11 pm

Re: To & or &amp;, that is the question..

Post by Kev »

I tried but the validator doesn't address entities in URL's.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: To & or &amp;, that is the question..

Post by jackpf »

It should.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: To & or &amp;, that is the question..

Post by alex.barylski »

Might depend on which doctype you have defined? I am quite sure that even transitional will error if & is not used in URI.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: To amp or meta amp, that is the question..

Post by josh »

Just be aware if you don't put & you run the risk of suffixing an ampersand with characters that happen to collide with a valid actual html entity. For instance if you had a URI parameter called 'copy', and you wrote &copy; the browser would get confused

Did you mean &copy; ( as in a ampersand followed by the word 'copy' followed by a semi-colon)
or did you mean &copy; (as in the actual copyright symbol)

So you see it is better to write & than &, not just because some validator says so, but because it is more bullet-proof.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: To & or &amp;, that is the question..

Post by John Cartwright »

Although slightly unconventional, you are better off using a different character other than & anyways (which can be configured in apache).
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: To & or &amp;, that is the question..

Post by josh »

How does that affect SEO?
Post Reply