Why should I use & instead of &?

2019-04-23 02:13发布

问题:

why should I use & instead of & when writing HTML for my site?

Where can I find a list of other symbols that I should be encoding? (the bar / too, right?)

What problems could I have if I paste the symbol right as it is into the html?

The thing is, I have a few affiliate links and I'm worried that, if I write them with the & in some cases, for some reasons, because of the specific browser or device... that the info in the url wouldn't be passed correctly.

Hopefully someone can clear my mind?

Thanks!

回答1:

From https://developer.mozilla.org/en-US/docs/Glossary/Entity

HTML has a set of four reserved characters that must be represented as entities. All other characters can be represented with entities as needed, but it is not mandatory. These are the entities used for those four reserved characters :

  • & (&) - Required, so that a browser does not misinterpret it as the beginning of an entity.
  • &lt; (<) - Required because otherwise a browser could misinterpret it as the beginning of a tag
  • &gt; (>) - Required because otherwise a browser could misinterpret it as the ending of a tag
  • &quot; (") - Required only within attributes value surrender by quote sign

See here for a full list of all HTML character entities - https://dev.w3.org/html5/html-author/charref



回答2:

The character '&' is reserved word which has special purpose. That's why you have to use it in specific way.

Here you can find the HTML Entities. http://www.w3schools.com/html/html_entities.asp