Another ampersand issue
I have basic html stored in my database, which includes html such as the anchor tag.
I am storing all & in the database as &
However, when the data is displayed back on the screen, the anchor tags stop working because the & in the links become &
.
The problem is, the rest of the content around the anchor tag should remain as &
For example
The database content might look like this
&l开发者_Go百科t;p>this is paragraph 1 & this is <a href="http://www.companyname.com/page.php?paragraph=2&sentence=4">paragraph 2</a>.</p>
The & in the url becomes &
which stops the url from working, but at the same time, the & in the
tab any any other tag should remain as &
Both the & in the href and in the <p>
should be encoded as &
to be valid
Source: http://htmlhelp.com/tools/validator
Probably you are looking for http://pl.php.net/manual/en/function.html-entity-decode.php
I assume you are storing the url separately in db.
See also: http://pl.php.net/manual/en/faq.html.php
The URL should still "work".
Although common convention is not to bother, HTML entities such as ampersands should always be encoded like &
or &
— you're already doing the latter, so the resulting URL should be valid.
e.g. <a href="page.php?a=1&a=2">link</a>
and <a href="page.php?a=1&a=2">link</a>
both present an anchor tag linking to the URI page.php?a=1&a=2
.
Update Ah, apparently in some browsers the hash in &
is seen as ending the URL.
What a mess! Use &
instead of &
... or, ideally, %26
.
精彩评论