PDA

View Full Version : Let's talk about validation for a second...


brianellisrules
Dec 31, 2003, 09:01 AM
Hello all. I'm bored at work so I figured I'd go through and validate all my webpages and whatnot. (Yeah, I'm *that* bored)

Anyhoo, I'm cruising along and everything is up to snuff for the most part, but then I try to validate my Christmas List...

http://www.brianellisrules.com/stories/?story=xmaslist

Turns out, the validator doesn't like all the links to amazon.com. What's up with that?

mnkeybsness
Dec 31, 2003, 04:03 PM
the validator does that because some special characters are used such as the ampersand '&' etc...

for valid html, you need to use the name codes (http://hotwired.lycos.com/webmonkey/reference/special_characters/)

unfortunately, the links will not work if you do that... it's kind of a php issue more than html... everything should work fine though even though it's not valid

mrjamin
Jan 1, 2004, 09:47 AM
Originally posted by mnkeybsness
unfortunately, the links will not work if you do that... it's kind of a php issue more than html... everything should work fine though even though it's not valid

eh? links should work absolutely fine! all my recent sites are valid XHTML, and have not had any problems with links in every browser i've tried. htmlspecialchars() (http://www.php.net/htmlspecialchars) or htmlentities() (http://php.net/htmlentities) on a url will sort out all the ampersands in querystrings etc.

edit: added links to php.net for functions

brianellisrules
Jan 1, 2004, 07:20 PM
The links are straight HTML code copied and pasted from the amazon.com webpage... there's no PHP involved there. I'm just wondering why they're not valid... I'm guessing the validator just flakes out on the long links.

Daveman Deluxe
Jan 1, 2004, 07:32 PM
It's not the length of the URI that the validator is pissed off about. In (X)HTML, the ampersand (&) character is used to denote the beginning of a character entity reference. In your page, the characters immediately after the ampersand do not refer to a character entity and there is no terminating semicolon. However, it's not going to cause you any problems because they are in URIs and not in page text.

By the way, if you're writing a webpage, do not type an actual ampersand into the text. Use the character entity reference "&" instead. Don't try to do it in URIs though.

It's a PHP issue because the web pages you are linking to are PHP and they use ampersand-delineated URIs as part of its system for submitting search/item requests.

This is one of those cases where the validators aren't perfect. It shouldn't be hard for a validator to ignore illegal characters in element attributes, but they aren't there yet.

Edit: On second glance, replacing ampersands with "&" will still link to the proper page, at least in Safari. I'm not positive about other browsers though.

mnkeybsness
Jan 1, 2004, 09:28 PM
Originally posted by Daveman Deluxe
It's not the length of the URI that the validator is pissed off about. In (X)HTML, the ampersand (&) character is used to denote the beginning of a character entity reference. In your page, the characters immediately after the ampersand do not refer to a character entity and there is no terminating semicolon. However, it's not going to cause you any problems because they are in URIs and not in page text.

By the way, if you're writing a webpage, do not type an actual ampersand into the text. Use the character entity reference "&" instead. Don't try to do it in URIs though.

It's a PHP issue because the web pages you are linking to are PHP and they use ampersand-delineated URIs as part of its system for submitting search/item requests.

This is one of those cases where the validators aren't perfect. It shouldn't be hard for a validator to ignore illegal characters in element attributes, but they aren't there yet.

Edit: On second glance, replacing ampersands with "&" will still link to the proper page, at least in Safari. I'm not positive about other browsers though.

that's what i said... only more in depth and makes a little more sense when you explain it.

mrjamin
Jan 2, 2004, 08:09 AM
Originally posted by Daveman Deluxe
Edit: On second glance, replacing ampersands with "&" will still link to the proper page, at least in Safari. I'm not positive about other browsers though.

Works in pretty much ever browser under the sun including Nutscrape, uhh i mean netscape 4 and IE 4.

Daveman Deluxe
Jan 2, 2004, 01:54 PM
Stupid me. When typing out character entity references in my earlier post, it converted them to proper ampersands. :rolleyes:

Edit: It still didn't work. Let's try it this way:

& a m p ;

Remove the spaces between each character when you do it for real, of course. :D :rolleyes: