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
Kev
Forum Newbie
Posts: 21 Joined: Tue Aug 25, 2009 9:11 pm
Post
by Kev » Thu Nov 12, 2009 1:28 pm
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
Post
by alex.barylski » Thu Nov 12, 2009 1:49 pm
Run your code through a validator and find out?
p.s-It's the latter form I do believe.
Cheers,
Alex
Kev
Forum Newbie
Posts: 21 Joined: Tue Aug 25, 2009 9:11 pm
Post
by Kev » Thu Nov 12, 2009 2:06 pm
I tried but the validator doesn't address entities in URL's.
jackpf
DevNet Resident
Posts: 2119 Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK
Post
by jackpf » Thu Nov 12, 2009 2:34 pm
It should.
alex.barylski
DevNet Evangelist
Posts: 6267 Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg
Post
by alex.barylski » Thu Nov 12, 2009 4:37 pm
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
Post
by josh » Sun Nov 15, 2009 10:58 pm
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 © the browser would get confused
Did you mean © ( as in a ampersand followed by the word 'copy' followed by a semi-colon)
or did you mean © (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.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sun Nov 15, 2009 11:05 pm
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
Post
by josh » Mon Nov 16, 2009 5:18 am
How does that affect SEO?