In C #, regular expressions can be used to filter HTML characters. For example, when verifying user input, HTML characters must be filtered to ensure security.
Using system. Text. regularexpressions;
RegEx. Replace (htmlcode, "] +> ","");
Convert HTML characters to DOM nodes and add them to the document dynamicallyThe dynamic conversion of strings to DOM nodes is often encountered in development, especially in the template engine.String conversion to DOM node itself is not difficult,
Yesterday in the company's website to see the Product Details page, found that only a company's JS product rotation effect will not be out, find a half-day, the program is the same, why? The original is the company alias is XIANDAHG, which contains
' function name: gethtmlcontent ' parameter:no--> the number of characters to be taken, txtcontent--> the string ' functionality to be processed: to intercept n-HTML characters from a string. Now the implementation is not perfect, the process is:
Dependent jar org.jsoup jsoup 1.8.3 Test:public static void Main (string[] args) {String ssss = " Test offline class questionnaire VR to work ";System.out.println (Jsoup.parse (SSSS). Getelementsbytag ("img"). Size (
Servlet filters special HTML characters of a string
(1) In some cases, when users enter data, we need to determine whether the data is valid, that is, to filter out whether the user input information contains special characters;
(2) directly add the
Regular Expressions match html characters to filter illegal charactersMatch an html Tag. The matching table is as follows:
[Ss] *
Or
[Ss] *?
The above two expressions Add "? "And one "? ", What is the difference?We know "?
Convert HTML characters to DOM nodes and add them to the document dynamically
The dynamic conversion of strings to DOM nodes is often encountered in development, especially in the template engine.String conversion to DOM node itself is not difficult,
This article address: http://blog.csdn.net/wusuopubupt/article/details/8817826
by Wusuopubupt
Tip: Just press ctrl+f to search for the escape characters you want to find.
Common tables:
No.
Word Form Memory
10 to remember
16
Htmlspecialchars (), htmlspecialchars_decode ()
Definition and usage
The htmlspecialchars () function converts some predefined characters into HTML objects.
The predefined characters are:& (And number) becomes & amp;"(Double quotation marks) into &
The Code is as follows: {code ...} & amp; lt; br & amp; gt; In the content will be removed. You can retain html tags for any operations such as $ e-& amp; gt; innerHtml. 8.18 update: {code...} the code is as follows:
$html =
Test
Htmlspecialchars (), Htmlspecialchars_decode ()
Definition and usage
The Htmlspecialchars () function converts some pre-defined characters to HTML entities.
The predefined characters are:& (and number) becomes &"(double quotes) becomes"' (single
Match an html tag. The matching table is as follows: [Ss] * Or [Ss] *? The above two expressions add "? "And one "? ", What is the difference?We know "? "In a regular expression is a wildcard: matches the previous subexpression zero or once, or
'Function name: gethtmlcontent' parameter: No --> Number of characters to be obtained, txtcontent --> string to be processed'Function: truncates n HTML-containing characters from a string. The current implementation method is not complete. The
///
/// Replace special characters in HTML
///
/// the text to be replaced.
/// the replaced text.
Public String htmlencode (string thestring)
{
Thestring = thestring. Replace (">", "> ");
Thestring = thestring. Replace ("Thestring = thestring.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.