About the meaning of amp;

Discussion in 'HTML' started by Hongyi Zhao, Jan 23, 2011.

  1. Hongyi Zhao

    Hongyi Zhao Guest

    Hongyi Zhao, Jan 23, 2011
    #1
    1. Advertising

  2. Hongyi Zhao

    dorayme Guest

    In article <>,
    Hongyi Zhao <> wrote:

    > Dear all,
    >
    > What's the differences between the following two urls:
    >
    > http://onlinelibrary.wiley.com/store/10.1002/pat.1839/asset/1839_ftp.pdf?v=1&a
    > mp;t=gj9lozx1&amp;s=e235af5557c0879d9490f00ce42b7ae5a58cbad3
    >
    > and
    >
    > http://onlinelibrary.wiley.com/store/10.1002/pat.1839/asset/1839_ftp.pdf?v=1&t
    > =gj9lozx1&s=e235af5557c0879d9490f00ce42b7ae5a58cbad3
    >
    > I find both of them can reach the destination file.
    >
    > Any hints will be highly appreciated. Thanks in advance.
    >



    In this case you get lucky because some or all browsers know the
    & means just that character and not the starting signal for an
    entity reference. As it happens, in this case, there is a t
    following and no sign of an ";" later (one criterion of an entity
    reference). The browser has some error correction algorithms for
    some rule breaking and can work this out easily enough. But in a
    different url you might not get so lucky. Best practice is to use
    &amp; to avoid this problem.

    --
    dorayme
     
    dorayme, Jan 23, 2011
    #2
    1. Advertising

  3. dorayme wrote:

    >> What's the differences between the following two urls:
    >>
    >> http://onlinelibrary.wiley.com/store/10.1002/pat.1839/asset/1839_ftp.pdf?v=1&a
    >> mp;t=gj9lozx1&amp;s=e235af5557c0879d9490f00ce42b7ae5a58cbad3
    >>
    >> and
    >>
    >> http://onlinelibrary.wiley.com/store/10.1002/pat.1839/asset/1839_ftp.pdf?v=1&t
    >> =gj9lozx1&s=e235af5557c0879d9490f00ce42b7ae5a58cbad3


    To answer the question asked, the difference is that the former has "&amp;"
    where the latter has "&", in two occurrences. I guess the OP knew that, but
    I still wanted to answer the question. :)

    URLs as such are strings used to access some resources, and it depends on
    the server how they are interpreted. In this case, at this very moment, both
    URLs refer to resources, though with restricted access (I get 403
    Forbidden), so one cannot decide whether the difference in the query part
    matters. Probably it matters, and probably the latter, with "&", is the one
    that should be used.

    >> I find both of them can reach the destination file.


    Well maybe, but here you are probably referring to the use of these strings
    in attribute value denotations in HTML, which is quite a different thing.
    URLs exist independently of HTML and need not have anything to do with it.

    The latter string, if entered as such in HTML, whether in an attribute value
    denotation or elsewhere, is syntactically erroneous. Well, technically it
    "only" contains undefined entity references, but that's really an error in
    practice. And in XHTML it is a well-formedness error, implying that a
    browser interpreting the data as genuine XHTML (i.e., XML with HTML tags)
    should refuse to render the document at all, just report the first error.

    > In this case you get lucky because some or all browsers know the
    > & means just that character and not the starting signal for an
    > entity reference.


    Rather, they know well what "&" signals, but the old practice is to parse
    the entity reference and find out that no such entity is defined, then guess
    that the string is to be taken literally as if it had "&amp;" instead of
    "&".

    > As it happens, in this case, there is a t
    > following and no sign of an ";" later (one criterion of an entity
    > reference).


    By classic (pre-XML) HTML rules, the semicolon is not required.

    > The browser has some error correction algorithms for
    > some rule breaking and can work this out easily enough. But in a
    > different url you might not get so lucky.


    Or in a different time. The HTML5 drafts list down a large number of new
    entities. Luckily they are not yet recognized by browsers, but some day they
    might.

    > Best practice is to use
    > &amp; to avoid this problem.


    In any flavor of HTML, yes. But this does not mean that "&amp;" should be
    used inside a URL. (It could, but that would be very odd, and it would have
    the literal meaning.) There is a difference between a URL like
    http://www.example.com/?foo&bar and the way in which this URL should be
    written in HTML markup, namely http://www.example.com/?foo&amp;bar

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
     
    Jukka K. Korpela, Jan 23, 2011
    #3
  4. Hongyi Zhao

    richard Guest

    On Sun, 23 Jan 2011 15:26:39 +0800, Hongyi Zhao wrote:

    > Dear all,
    >
    > What's the differences between the following two urls:
    >
    > http://onlinelibrary.wiley.com/stor...mp;s=e235af5557c0879d9490f00ce42b7ae5a58cbad3
    >
    > and
    >
    > http://onlinelibrary.wiley.com/stor...x1&s=e235af5557c0879d9490f00ce42b7ae5a58cbad3
    >
    > I find both of them can reach the destination file.
    >
    > Any hints will be highly appreciated. Thanks in advance.
    >
    > BR.


    The key here is the "?".
    Neither & nor &amp is permitted to the left of it.
    The ? denotes the beginning of variable values. So certain characters will
    be treated as operators, not textual characters as in the body of the page.

    I've always rather detested the fact that the W3 validator begins ringing
    up errors when it hits the ?. Because nobody bothered to put in a command
    that said, "Stop here and move on to next line".
    So well meaning people who have validated their pages appease the validator
    and include &amp. When technically it should be just "&".

    I'll just bet that if you plugged that URL into IE4 it would have a holy
    fit.
     
    richard, Jan 23, 2011
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DC Gringo
    Replies:
    3
    Views:
    6,150
    mikeb
    Aug 19, 2004
  2. DC Gringo

    encoding of "&" vs "&amp;" in url

    DC Gringo, Aug 4, 2005, in forum: ASP .Net
    Replies:
    8
    Views:
    16,960
    davitz38
    Feb 5, 2010
  3. Replies:
    1
    Views:
    697
    Rosanne
    Oct 11, 2005
  4. FoundThisOnline

    &amp; problem with hyperlink control

    FoundThisOnline, Oct 11, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    2,888
    FoundThisOnline
    Oct 11, 2005
  5. Replies:
    4
    Views:
    773
Loading...

Share This Page