Forums, chat rooms, in the filter HTML tags
Abstract: The Forum, chat rooms are open systems, each an authority in which the user can speak freely …
Let us take a look at how these markers filtered. As we all know, HTML tag is bracketed by the two Tsim "<",">" and composition of some of these statements, such as, as long as we receive the HTML language in the corresponding change "<",">" <and> in the back on it. Now it more clear thinking. Now let us look at this process in the Java program in how to achieve in order to save space, I can only write a filter function.
Public String htmlFilter (String inputString);
If (inputString.length () = = 0 | | inputString = = null)
(
Return inputString;
)
/ / / Receive if the string is empty value or length of zero will return the string,
/ / Empty string because it is impossible * the link "and>
StringBuffer str = new StringBuffer (inputString.length () +6);
/ / Create a buffer space
Char c ='';
For (int i = 0; i <inputString.length (); i + +)
(
C = inputString.charAt (i) / / each scan input string, removed inputString first i +1 characters
If (c = ='<')
(
Str.append ("<");
) / / C: If '<', in the buffer str adding "<" instead of '<'
Else if (c = ='>')
(
Str.append ("<");
) / / C if the '>', in the buffer str add ">" instead of '>'
Else
(
Str.append (c); / / If neither '<' nor '>' c directly to the values enshrined in the buffer
)
)
Return str.toString (); / / filtration HTML tags string
)
You see, the problem was a simple function of the Java resolved. You just add it to your forums or chat on the proceedings held.
↑ Back
Tags: forums, java filter
Releated Java Articles
June 15, 2007 | Filed Under API for Java |






