超链接中的“&"号导致W3C验证失败 [英] Ampersands in hyperlinks cause W3C validation to fail
问题描述
我遇到了一个问题.我编写符合标准的好代码,只是为了使它在某些超链接URL中由于&"号而失败.
I have a reacurring problem. I code nice standards compliant code only to have it fail due to ampersands within some of the hyperlink urls.
任何人都知道解决方法或为此破解吗.
Does anyone know of a work around or hack for this.
谢谢
推荐答案
您应 URL编码超链接,因此所有字符都将转换为有效的ASCII格式,并且不包含任何(X)HTML实体.
You should URL Encode the hyperlinks, so all characters are turned into a valid ASCII format and don't contain any (X)HTML entities.
对于C#,请使用 HttpUtility.UrlEncode
,对于PHP urlencode
,对于JavaScript encodeURI
,等等...为您使用的语言找到正确的方法并不难.
For C# use HttpUtility.UrlEncode
, for PHP urlencode
, for JavaScript encodeURI
, etc... Finding the right method for the language you're using shouldn't be that hard.
这篇关于超链接中的“&"号导致W3C验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!