---
title: "过滤HTML"
author: "Will_Turner"
date: "2012-06-11T22:13:05Z"
tags: ["过滤HTML"]
categories: ["编程语言"]
slug: "html"
draft: false
lastmod: "2012-06-11T22:13:05Z"
id: 1558703
url: "https://will-turner.iteye.com/blog/1558703"
---

```
public static String filterHTML(String sHtml) {
	if (sHtml == null || "".equals(sHtml)) {
		return "";
	}
	return sHtml.replace("&", "&amp;").replace(" ", "&nbsp;")
				.replace("<", "&lt;").replace(">", "&gt;")
				.replace("\"", "&quot;").replace("\r\n", "<br>");
}
```