Ways to filter HTML characters

Source: Internet
Author: User

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 and characters are filtered out.

public static string nohtml (String htmlstring)//Remove HTML tag
{
Delete Script
htmlstring = Regex.Replace (htmlstring, @ "<script[^>]*?>.*?</script>", "", regexoptions.ignorecase);
Delete HTML
htmlstring = Regex.Replace (htmlstring, @ "< (. [ ^>]*) > "," ", regexoptions.ignorecase);
htmlstring = Regex.Replace (htmlstring, @ "([\ r \ n]) [\s]+", "", regexoptions.ignorecase);
htmlstring = Regex.Replace (htmlstring, @ "-and", "", regexoptions.ignorecase);
htmlstring = Regex.Replace (htmlstring, @ "<!--. *", "", regexoptions.ignorecase);

Htmlstring = Regex.Replace (htmlstring, @ "& (quot| #34);", "\" ", regexoptions.ignorecase);
Htmlstring = Regex.Replace (htmlstring, @ "& (amp| #38);", "&", Regexoptions.ignorecase);
Htmlstring = Regex.Replace (htmlstring, @ "& (lt| #60);", "<", regexoptions.ignorecase);
Htmlstring = Regex.Replace (htmlstring, @ "& (gt| #62);", ">", Regexoptions.ignorecase);
Htmlstring = Regex.Replace (htmlstring, @ "& (nbsp| #160);", "", regexoptions.ignorecase);
Htmlstring = Regex.Replace (htmlstring, @ "& (iexcl| #161);", "\xa1", regexoptions.ignorecase);
Htmlstring = Regex.Replace (htmlstring, @ "& (cent| #162);", "\xa2", regexoptions.ignorecase);
Htmlstring = Regex.Replace (htmlstring, @ "& (pound| #163);", "\xa3", regexoptions.ignorecase);
Htmlstring = Regex.Replace (htmlstring, @ "& (copy| #169);", "\xa9", regexoptions.ignorecase);
Htmlstring = Regex.Replace (htmlstring, @ "(\d+);", "", regexoptions.ignorecase);

Htmlstring.replace ("<", "");
Htmlstring.replace (">", "");
Htmlstring.replace ("\ r \ n", "");
htmlstring = Htmlstring.replace ("[\\s]{2,{", "" ");
htmlstring = Htmlstring.replace ("(<[b| b][r| r]/*>) +| (<[p| P] (. | \\n) *?>) "," \ n "); <br>
htmlstring = Htmlstring.replace ("(\\s*&[n| n][b| b][s| s][p| p];\\s*) + "," "); &nbsp;
htmlstring = Htmlstring.replace ("< (. | \\n) *?> ", String. Empty); Any other tags
htmlstring = Htmlstring.replace ("", "&nbsp;");
htmlstring = Htmlstring.replace ("&nbsp;", "");
htmlstring = Htmlstring.replace ("\ r \ n", "<br>");
htmlstring = htmlstring.replace ("=", "");
htmlstring = htmlstring.replace ("%", "");
htmlstring = Htmlstring.replace ("'", "" ");
htmlstring = Htmlstring.replace ("Select", "");
htmlstring = Htmlstring.replace ("Insert", "");
htmlstring = htmlstring.replace ("delete", "");
htmlstring = Htmlstring.replace ("or", "");
htmlstring = Htmlstring.replace ("exec", "");
htmlstring = Htmlstring.replace ("--", "" ");
htmlstring = Htmlstring.replace ("and", "");
htmlstring = Htmlstring.replace ("where", "");
htmlstring = Htmlstring.replace ("Update", "");
htmlstring = Htmlstring.replace ("Script", "");
htmlstring = Htmlstring.replace ("iframe", "");
htmlstring = Htmlstring.replace ("Master", "");
htmlstring = Htmlstring.replace ("exec", "");
htmlstring = Htmlstring.replace ("and", "");
htmlstring = Htmlstring.replace ("and", "");
htmlstring = Htmlstring.replace ("and", "");
htmlstring = Htmlstring.replace ("and", "");
htmlstring = Htmlstring.replace ("and", "");
htmlstring = Htmlstring.replace ("and", "");
htmlstring = Htmlstring.replace ("and", "");

htmlstring = Htmlstring.replace ("exists", "" ");
htmlstring = Htmlstring.replace ("Drop", "");
htmlstring = Htmlstring.replace ("996008E", "");
htmlstring = Htmlstring.replace ("AR (124)", "");
htmlstring = Htmlstring.replace ("1and", "");
htmlstring = Htmlstring.replace ("0and", "");
htmlstring = Htmlstring.replace ("Chr", "" ");

htmlstring = HttpContext.Current.Server.HtmlEncode (htmlstring). Trim ();

return htmlstring;
}

Ways to filter HTML characters

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.