Ampersand in link description text?

I check my site using http://validator.w3.org and have a problem when there is a link in the description text &.

This is taken from the source:

<a class='tag' href='/php/iphone software.php?function=developer&amp;dev=witch%26wizards+inc.&amp;store=143441'>witch&wizards inc.</a>

This gives this error in the validator:

Row 188, Column 540: cannot generate a system identifier for the "wizards" of the general entity

... 6wizards + inc. & store = 143441 '> witch & wizards inc.

βœ‰ An entity reference was found in the document, but no reference to this name was specified

If I urlencode the description, then the check passes, but the user then sees the text displayed by urlencoded, i.e.

Developer witch% 26wizards + inc.

However, I believe that it is much more convenient for the user if it was displayed uncoded, i.e.

Developer witchers & wizards inc.

, ?

+3
3

:

, URL- %26.

, - - , - HTML &amp;.

HTML :

<a class='tag' href='/php/iphone%20software.php?function=developer&amp;dev=witch%26wizards+inc.&amp;store=143441'>witch&amp;wizards inc.</a>
+8

&amp;, %26

EDIT: woah, & SO.

+2

& URL %26, &amp; ( %20) & &amp;:

<a class='tag' href='/php/iphone%20software.php?function=developer%26dev=witch%26wizards+inc.%26store=143441'>witch&amp;wizards inc.</a>

Note that there is a difference between the URL encoding used to encode URLS and the HTML objects used to encode display text in HTML. For example, if you want to display text <br/>in HTML, you must encode it as &lt;br/&gt;, but in the URL it will %3Cbr%2F%3E.

Use htmlentities()to encode special characters as HTML objects in PHP.

+1
source

Source: https://habr.com/ru/post/1783006/


All Articles