如何剥离或逃生的HTML标签的Android [英] How to strip or escape html tags in Android
问题描述
PHP有用strip_tags
函数地带HTML和字符串中的PHP代码。
PHP has strip_tags
function which Strip HTML and PHP tags from a string.
是否必须的android逃脱HTML?
Does android have a means to escape html?
推荐答案
在答案的解决方案,通过@sparkymat链接到一般要求要么正则表达式 - 这是一个容易出错的方法 - 或安装第三方库,如< A HREF =http://jsoup.org/> jsoup 或杰里科。在Android设备上更好的解决办法就是要利用Html.fromHtml()函数的:
The solutions in the answer linked to by @sparkymat generally require either regex - which is an error-prone approach - or installing a third-party library such as jsoup or jericho. A better solution on Android devices is just to make use of the Html.fromHtml() function:
public String stripHtml(String html) {
return Html.fromHtml(html).toString();
}
本使用内置的HTML解析器来构建一个跨区
重新输入HTML的presentation没有任何html标签Android的。而跨度的标记,然后通过转换输出回字符串剥离。
This uses Android's built in Html parser to build a Spanned
representation of the input html without any html tags. The "Span" markup is then stripped by converting the output back into a string.
这篇关于如何剥离或逃生的HTML标签的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!