SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    boiler up blackdog's Avatar
    Join Date
    Jul 2002
    Location
    Purdue
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    "&" and valid html

    I have a phone reviews site and I have AT&T. When I try to validate my site, the "&" causes all sorts of errors.

    For example...


    <LI>Line 151, column 52: entity was defined here

    <td class="navnorm"><a class="navtop1" href="at&t.php">AT&T</a></td>

    <LI>Line 151, column 63: cannot generate system identifier for general entity "T"

    ...class="navnorm"><a class="navtop1" href="at&t.php">AT&T</a></td>


    anyone know how to fix this so my site validates? thanks!

  2. #2
    SitePoint Wizard silver trophy KLB's Avatar
    Join Date
    Nov 2003
    Location
    Maine USA
    Posts
    3,781
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Simply use &amp; any time you want &.
    Ken Barbalace: EnvironmentalChemistry.com (Blog, Careers)
    InternetSAR.org
    Volunteers Assist Search and Rescue via Internet
    My Firefox Theme: Classic Compact
    Based onFirefox's default theme but uses much less window space

  3. #3
    SitePoint Addict
    Join Date
    May 2003
    Location
    Auckland
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You really shouldn't use ampersand in your file names.

    Change it to at-and-t.html or atandt.html

  4. #4
    boiler up blackdog's Avatar
    Join Date
    Jul 2002
    Location
    Purdue
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the advice guys!

  5. #5
    SitePoint Wizard silver trophy KLB's Avatar
    Join Date
    Nov 2003
    Location
    Maine USA
    Posts
    3,781
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Imminent
    You really shouldn't use ampersand in your file names.

    Change it to at-and-t.html or atandt.html
    Very good point! I simply noticed the question about ampersand and did not notice it was being used in a URL. & should only be used in URL query strings (e.g. bla.html?variable1=yes&amp;variable2=no)
    Ken Barbalace: EnvironmentalChemistry.com (Blog, Careers)
    InternetSAR.org
    Volunteers Assist Search and Rescue via Internet
    My Firefox Theme: Classic Compact
    Based onFirefox's default theme but uses much less window space

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:

    I seem to recall that there's a property you can set in .htaccess in Apache that will allow you to specify &amp; instead of & for query string variables. I forget what it is specifically, and I'm not sure if there's one for IIS, but I thought I'd mention that.


  7. #7
    SitePoint Wizard silver trophy KLB's Avatar
    Join Date
    Nov 2003
    Location
    Maine USA
    Posts
    3,781
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by compuwhiz7
    Off Topic:

    I seem to recall that there's a property you can set in .htaccess in Apache that will allow you to specify &amp; instead of & for query string variables. I forget what it is specifically, and I'm not sure if there's one for IIS, but I thought I'd mention that.


    ?????

    If you use &amp; instead of & in the querystrings of links, the webbrowser will translate &amp; into & and only submit & when a link is clicked on. There is no need for a special configuration Apache or IIS.
    Ken Barbalace: EnvironmentalChemistry.com (Blog, Careers)
    InternetSAR.org
    Volunteers Assist Search and Rescue via Internet
    My Firefox Theme: Classic Compact
    Based onFirefox's default theme but uses much less window space

  8. #8
    SitePoint Addict m2k's Avatar
    Join Date
    Oct 2003
    Location
    Philadelphia
    Posts
    209
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, an example:

    you create a site with valid XHTML and CSS and want to include links at the bottom of the pages for each. If you copy and paste the url's (generated by the W3C site) of your validated pages into your links, don't forget that the url's have "&"s in them. Go through and change them to &amp's or, technically, you will wind up with invalid XHTML despite just validating it (if that makes sense).

  9. #9
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KLB
    ?????

    If you use &amp; instead of & in the querystrings of links, the webbrowser will translate &amp; into & and only submit & when a link is clicked on. There is no need for a special configuration Apache or IIS.
    Yep, but I do seem to recall that you can specify what delimiter to use. I honestly can't remember what the application was, but I do remember the existence of such a setting.

  10. #10
    SitePoint Enthusiast
    Join Date
    Jan 2004
    Location
    Glasgow, Scotland
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The & think in the w3c validator is a bug in the validation system. Though the & throughs an error, it's no actually invalid code. It's just that the vallidator script is not smart enough to work it out.

    The w3c validator script is a tool to help you produce valid code. It is not the final word on what is actually valid or not. That is left to the various specifications and guidlines. When using a vallidator, it is more important to understand why your code fails and be able to make an informed decition based on the results than it is to get a clean sheet.

  11. #11
    SitePoint Wizard silver trophy KLB's Avatar
    Join Date
    Nov 2003
    Location
    Maine USA
    Posts
    3,781
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rincewind
    The & think in the w3c validator is a bug in the validation system. Though the & throughs an error, it's no actually invalid code. It's just that the vallidator script is not smart enough to work it out.
    Using the & sign directly attached to a string of characters when &amp; should be used is actually a validation error and not a bug with validators. The reason is that the ampere is a modifier that lets the browser know that the next characters are a code for a specific ASCII character. Originally (circa Netscape 1 and/or 2) if one used the '&' sign, the browser would try to convert the attached string of characters into an ASCII character, which frequently caused problems. Because people had a bad habit of not using '&' correctly, browsers were modified to compensate just as we have seen browsers modified to deal with other bad coding habits like not closing a table.
    Ken Barbalace: EnvironmentalChemistry.com (Blog, Careers)
    InternetSAR.org
    Volunteers Assist Search and Rescue via Internet
    My Firefox Theme: Classic Compact
    Based onFirefox's default theme but uses much less window space

  12. #12
    SitePoint Enthusiast
    Join Date
    Jan 2004
    Location
    Glasgow, Scotland
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using & in your plain text is an error since &amp; is the correct method. However, inside url's or as I often find inside my javascript code, the conventions of html do not and should not apply. The file naming conventions are determined by the operating system of you server not the w3c. If the OS allows AT&T.php as a file name the the URL to that file should be AT&T.php not AT&amp;T.php. Your browser corrects the error of the &amp; in the url and sends AT&T.php to the server. If you actually tried bypassing the browser (e.g. use an ftp, ssh or telnet client) and asked the server for the file AT&amp;T.php then you'd get a 404 error. Thus using AT&amp;T.php is incorrect file name.

  13. #13
    SitePoint Zealot Hulkur's Avatar
    Join Date
    Oct 2001
    Location
    Estonia
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in php.ini
    Code:
    arg_separator.output = "&amp;"
    or .htaccess
    Code:
    php_value arg_separator.output &amp;
    lets you specify wether to use & or &amp; (for automatic attaching of session ID to url)
    (2B) or (not 2B) = FF

  14. #14
    I am obstructing justice. bronze trophy fatnewt's Avatar
    Join Date
    Jul 2002
    Location
    Ottawa, Canada
    Posts
    1,766
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rincewind
    Using & in your plain text is an error since &amp; is the correct method. However, inside url's or as I often find inside my javascript code, the conventions of html do not and should not apply. The file naming conventions are determined by the operating system of you server not the w3c. If the OS allows AT&T.php as a file name the the URL to that file should be AT&T.php not AT&amp;T.php. Your browser corrects the error of the &amp; in the url and sends AT&T.php to the server. If you actually tried bypassing the browser (e.g. use an ftp, ssh or telnet client) and asked the server for the file AT&amp;T.php then you'd get a 404 error. Thus using AT&amp;T.php is incorrect file name.
    Uhm, this isn't true.

    True, &amp; is not a part of the actual URL. But it is the correct way to reference the ampersand character in (X)HTML. Since you need to reference this character in the URL, you use &amp; (because even though this is a URL, it's a part of an (X)HTML document). The browser knows this, so it translates it for you when it actually goes to this page.

    Here it is in the XHTML recommendation:

    Quote Originally Posted by W3C on XHTML
    For example, when the href attribute of the a element refers to a CGI script that takes parameters, it must be expressed as http://my.site.dom/cgi-bin/myscript.pl?class=guest&amp;name=user rather than as name=userhttp://my.site.dom/cgi-bin/myscript.pl?class=guest&name=usr.
    This becomes especially important if your XHTML document is being read by an XML interpereter, which is why it's mentioned here... but the same applies for HTML.
    Colin Temple [twitter: @cailean]
    Web Analyst at Napkyn



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •