本文介绍了在评论标签中转义html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

转义html是正确的 - 它将删除 > 等。 p>

ive遇到一个我在注释标签内输出文件名的问题,例如。 <! - $ {filename} - >



当然如果你不逃避,所以它变成:
<! - < c:out value =$ {filename}/> - >



问题是,如果该文件在名称中具有 - ,所有的html都会被拧紧,因为你不允许有<! - - - >



标准的html转义不会转义这些破折号,我想知道是否有人熟悉一个简单/标准的方式来逃避他们。

解决方案

当然,解析一个注释是由浏览器决定的。



没有什么打击我是一个明显的解决方案在这里,所以我建议你str_replace这些双破折号。


escaping html is fine - it will remove <'s and >'s etc.

ive run into a problem where i am outputting a filename inside a comment tag eg. <!-- ${filename} -->

of course things can be bad if you dont escape, so it becomes:<!-- <c:out value="${filename}"/> -->

the problem is that if the file has "--" in the name, all the html gets screwed, since youre not allowed to have <!-- -- -->.

the standard html escape doesnt escape these dashes, and i was wondering if anyone is familiar with a simple / standard way to escape them.

解决方案

Definition of a HTML comment:

Of course the parsing of a comment is up to the browser.

Nothing strikes me as an obvious solution here, so I'd suggest you str_replace those double dashes out.

这篇关于在评论标签中转义html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 18:53
查看更多