Remove style, JavaScript, and CSS code from HTML in ASP

Source: Internet
Author: User

ASP Functions Code Copy code The Code is as follows: <%
Function removehtml (STR)
Dim objregexp, match, strhtml
If isnull (STR) then
STR = ""
End if
Strhtml = Str
Strhtml = Replace (replace (strhtml, vblf, ""), vbcr, ""), vbcrlf ,"")

Set objregexp = new Regexp
Objregexp. ignorecase = true
Objregexp. Global = true

Objregexp. pattern = "<SCRIPT [^>] *?>. *? </SCRIPT>"
Strhtml = objregexp. Replace (strhtml ,"")

Objregexp. pattern = "<style [^>] *?>. *? </Style>"
Strhtml = objregexp. Replace (strhtml ,"")

Objregexp. pattern = "<. +?> "
Strhtml = objregexp. Replace (strhtml ,"")

Set objregexp = nothing

Removehtml = strhtml
End Function
%>

PHP Code copy Code the code is as follows: $ search = array ("' 'si ", // remove JavaScript
" ' 'si ", // remove CSS
" '<[/!] *? [^ <>] *?> 'Si ", // remove the HTML tag
" ' ] *?> 'Si ", // remove the annotation mark
" '([Rn]) [s] + '", // remove the blank character
"'& (quot | #34);' I", // Replace the HTML Entity
"'& (Amp | #38 ); 'I ",
"' & (LT | #60); 'I ",
"' & (GT | #62); 'I ",
"'& (nbsp | #160);' I",
"'& (iexcl | #161);' I ",
"'& (cent | #162);' I",
"'& (pound | #163);' I ",
"'& (copy | #169);' I",
"'(D +); 'E "); // run as PHP Code

$ Replace = array ("",
"",
"",
"",
"\ 1 ",
"\"",
"&",
"<",
"> ",
"",
CHR (1, 161 ),
CHR (1, 162 ),
CHR (1, 163 ),
CHR (1, 169 ),
"CHR (\ 1 )");
// $ Document is the string to be processed. if the source is a file, you Can $ document = file_get_contents ('HTTP: // www.sina.com.cn ');
$ Out = preg_replace ($ search, $ replace, $ document );
Echo $ out;
?>

Save it as get. php.

Related Article

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.