Menu

#22 URL encoding in links

open
nobody
General (3)
5
2004-12-09
2004-12-09
LT-P
No

When trying to validate the pages generated by phpix2,
I get those errors:

___

Line 32, column 203: cannot generate system identifier
for general entity "user"

...m=%23%23NONE%23%23&dispsize=Original&user=&pic=directory.jpg&width=92&height=

An entity reference was found in the document, but
there is no reference by that name defined. Often this
is caused by misspelling the reference name, unencoded
ampersands, or by leaving off the trailing semicolon
(;). The most common cause of this error is unencoded
ampersands in URLs as described by the WDG in
"Ampersands in URLs".

Entity references start with an ampersand (&) and end
with a semicolon (;). If you want to use a literal
ampersand in your document you must encode it as
"&" (even inside URLs!). Be careful to end entity
references with a semicolon or your entity reference
may get interpreted in connection with the following
text. Also keep in mind that named entity references
are case-sensitive; &Aelig; and æ are different
characters.

___

This problem is explained there:
http://www.htmlhelp.com/tools/validator/problems.html#amp

___
Ampersands (&'s) in URLs

Another common error occurs when including a URL which
contains an ampersand ("&"):

<!-- This is invalid! --> <a
href="foo.cgi?chapter=1&section=2">...</a>

This example generates an error for "unknown entity
section" because the "&" is assumed to begin an entity.
In many cases, browsers will recover safely from the
error, but the example used here will cause the link to
fail in Netscape 3.x (but not other versions of
Netscape) since it will assume that the author intended
to write &sect;ion, which is equivalent to 告on.

To avoid problems with both validators and browsers,
always use &amp; in place of & when writing URLs in HTML:

<a href="foo.cgi?chapter=1&amp;section=2">...</a>

Note that replacing & with &amp; is only done when
writing the URL in HTML, where "&" is a special
character (along with "<" and ">"). When writing the
same URL in a plain text email message or in the
location bar of your browser, you would use "&" and not
"&amp;". With HTML, the browser translates "&amp;" to
"&" so the Web server would only see "&" and not
"&amp;" in the query string of the request.
___

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.