开发者

PHP Tidy encodes comment

I am making use of PHP tidy and I've been given a situation where a user has placed a comment within a href attribute, like so:

<a href="<!-- Comment -->">Link</a>

When I pass it through Tidy, it returns:

<a href="&lt;!-- Comment --&gt;">Link</a>

I am guessing this 开发者_JAVA百科is Tidy's way of correcting this? It makes sense, but is there a way to stop this behaviour, other than not using Tidy?!

I have tried switching on/off the configuration options: literal-attributes, fix-bad-comments and preserve-entities. But these do not seem to turn off this effect


I don't think this is valid HTML even. You can't put tags inside attribute values.


Before passing the html through PHP tidy, look for comments (regexp, perhaps?) and encode them somehow. Then unencode after using tidy.

One example of how to encode comments would be to set the href as comment://n, where n is the index of the original comment text, which is stored in an array.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜