LZ骨骼一下 fanhexie.tk 偶自己做了个 遍历词库 Imports System.IO Partial Class wordtool_dohx Inherits System.Web.UI.Page Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load Dim strRtnWord As String Dim strWord As String = Request.Form("str") Dim strFilter As String = Request.Form("strFilter") 'Dim strWord As String = "今天我们去游行哈哈哈 反日吧。。个哦个哦个哦过" 'Dim strFilter As String = "/*/" If Not IsPostBack Then strRtnWord = doFilterword(strWord, strFilter) Response.Write(strRtnWord) Response.End() End If End Sub Public Function doFilterword(ByVal i_strWord As String, ByVal i_strFilter As String) As String Dim strTemp As String = "" Dim strArr As String = "" Dim strFilter As String = "" strTemp = i_strWord For i As Integer = 0 To CType(Application("arrList"), ArrayList).Count - 1 strArr = CType(Application("arrList"), ArrayList)(i).ToString strFilter = "" For j As Integer = 0 To strArr.Length - 1 strFilter = strFilter & strArr(j) & i_strFilter Next strTemp = strTemp.Replace(strArr, strFilter) Next Return strTemp End Function End Class<%@ Application Language="VB" %> <%@ Import Namespace="System.IO" %> <script runat="server">
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs on application startup loadWordData() End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs on application shutdown End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when an unhandled error occurs End Sub Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when a new session is started End Sub Sub Session_End(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when a session ends. ' Note: The Session_End event is raised only when the sessionstate mode ' is set to InProc in the Web.config file. If session mode is set to StateServer ' or SQLServer, the event is not raised. End Sub Public Sub loadWordData() Dim arrList As ArrayList arrList = New ArrayList Dim sr As StreamReader = New StreamReader(Server.MapPath("~/") + "\word.txt") Do While sr.Peek() >= 0 arrList.Add(Trim(sr.ReadLine())) Loop sr.Close()
Application("arrList") = arrList End Sub </script>
在后台设置过滤字符 void Application_BeginRequest(object sender, EventArgs e) { for (int i=0; i < Request.Form.Count;i++) { if (Request.Form[i].ToString() == "__VIEWSTATE") continue; if (IsM(Request.Form[i].ToString())) { Response.Write("您提交的内容中含有非法字符."); Response.End(); } } } protected bool IsM(string InText) { string word = @""; if (InText == null) return false; if (Regex.IsMatch(InText,word)) return true; return false; }
Imports System.IO
Partial Class wordtool_dohx
Inherits System.Web.UI.Page
Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
Dim strRtnWord As String
Dim strWord As String = Request.Form("str")
Dim strFilter As String = Request.Form("strFilter") 'Dim strWord As String = "今天我们去游行哈哈哈 反日吧。。个哦个哦个哦过"
'Dim strFilter As String = "/*/"
If Not IsPostBack Then strRtnWord = doFilterword(strWord, strFilter) Response.Write(strRtnWord)
Response.End()
End If End Sub Public Function doFilterword(ByVal i_strWord As String, ByVal i_strFilter As String) As String
Dim strTemp As String = ""
Dim strArr As String = ""
Dim strFilter As String = ""
strTemp = i_strWord
For i As Integer = 0 To CType(Application("arrList"), ArrayList).Count - 1
strArr = CType(Application("arrList"), ArrayList)(i).ToString
strFilter = ""
For j As Integer = 0 To strArr.Length - 1
strFilter = strFilter & strArr(j) & i_strFilter
Next strTemp = strTemp.Replace(strArr, strFilter)
Next
Return strTemp
End Function
End Class<%@ Application Language="VB" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application startup
loadWordData()
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application shutdown
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
End Sub Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a new session is started
End Sub Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a session ends.
' Note: The Session_End event is raised only when the sessionstate mode
' is set to InProc in the Web.config file. If session mode is set to StateServer
' or SQLServer, the event is not raised.
End Sub
Public Sub loadWordData()
Dim arrList As ArrayList
arrList = New ArrayList Dim sr As StreamReader = New StreamReader(Server.MapPath("~/") + "\word.txt") Do While sr.Peek() >= 0
arrList.Add(Trim(sr.ReadLine()))
Loop
sr.Close()
Application("arrList") = arrList
End Sub
</script>
void Application_BeginRequest(object sender, EventArgs e)
{
for (int i=0; i < Request.Form.Count;i++)
{
if (Request.Form[i].ToString() == "__VIEWSTATE") continue;
if (IsM(Request.Form[i].ToString()))
{
Response.Write("您提交的内容中含有非法字符.");
Response.End();
} }
}
protected bool IsM(string InText)
{
string word = @"";
if (InText == null)
return false;
if (Regex.IsMatch(InText,word))
return true;
return false;
}
看来csdn没这么先进的过滤系统。
{
Regex.Replace("我操|我日|操你妈|靠|傻逼文本","我操|我日|操你妈|靠|傻逼","*");
}
while(Regex.Match(我操|我日|操你妈|靠|傻逼文本","我操|我日|操你妈|靠|傻逼").Success)
{
Regex.Replace("我操|我日|操你妈|靠|傻逼文本","我操|我日|操你妈|靠|傻逼","*");
}
先判断是不是匹配,然后替换