开发者

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 &#38; which stops the url from working, but at the same time, the & in the

tab any any other tag should remain as &#38;


Both the & in the href and in the <p> should be encoded as &amp; 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 &amp; or &#38; — you're already doing the latter, so the resulting URL should be valid.

e.g. <a href="page.php?a=1&amp;a=2">link</a> and <a href="page.php?a=1&#38;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 &#38; is seen as ending the URL.

What a mess! Use &amp; instead of &#38; ... or, ideally, %26.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜