0
我们的项目是基于Java的,所以我有这样的,例如:如何使用时删除HTML标签的<bean:写/>
<meta name="description" content="<bean:write name="htmlHeadDescription" ignore="true"/>"/>
的事情是,这个htmlHeadDescription
似乎是HTML
和不是纯文字。
所以 - 有没有办法直接剥离HTML标签?
我们的项目是基于Java的,所以我有这样的,例如:如何使用时删除HTML标签的<bean:写/>
<meta name="description" content="<bean:write name="htmlHeadDescription" ignore="true"/>"/>
的事情是,这个htmlHeadDescription
似乎是HTML
和不是纯文字。
所以 - 有没有办法直接剥离HTML标签?
我做到了,有点像manually
......像这样:
而是具有:
<meta name="description" content="<bean:write name="htmlHeadDescription" ignore="true"/>"/>
现在我有这样的:
<%
// Remove any bad stuff - ONLY for the meta description tag ..
request.setAttribute("htmlDescriptionStripped",
request.getAttribute("htmlHeadDescription").toString()
// remove any eventual remaining HTML tags ..
.replaceAll("\\<(.*?)>","")
// make everything on one row ..
.replaceAll("\\s+"," ")
// remove any eventual CSS code ..
.replaceAll("(@media|.|#)(.*)\\{(.*)\\}","")
);
%>
<meta name="description" content="<bean:write name="htmlDescriptionStripped" ignore="true"/>"/>
它看起来像它的工作:)
你不能直接做,但转义html内容不会返回纯文本。 –