How to remove STYLE,JAVASCRIPT,CSS code from HTML in ASP application techniques

Source: Internet
Author: User
Tags chr html tags
ASP function code
Copy Code code 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
%>

The code in PHP
Copy Code code as follows:

<?php
$search = Array ("' <script[^>]*?>.*?</script> ' si",//Remove JavaScript
"' <style[^>]*?>.*?</style> ' si",//Remove CSS
"' <[/!] *? [^<>]*?> ' Si ',//Remove HTML tags
"' <!--[/!] *? [^<>]*?> ' Si ',//Remove comment mark
"' ([RN]) [s]+ '],//remove white space characters
"' & (quot| #34); ' I ",//Replace 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 (161),
Chr (162),
Chr (163),
Chr (169),
"Chr (\1)");
$document for strings to be processed if the source is a file can $document = file_get_contents (' http://www.sina.com.cn ');
$out = Preg_replace ($search, $replace, $document);
Echo $out;
?>

Save as get.php can be.
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.