文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>去除html标记 ...

去除html标记 ...

时间:2010-08-17  来源:jlds123

 /// 去除HTML标记
        public static string NoHTML(string strHtml)
        {
            strHtml= Regex.Replace(strHtml, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);          

 strHtml= Regex.Replace(strHtml, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
            strHtml= Regex.Replace(strHtml, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
            strHtml= Regex.Replace(strHtml, @"-->", "", RegexOptions.IgnoreCase);
            strHtml= Regex.Replace(strHtml, @"<!--.*", "", RegexOptions.IgnoreCase);

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

            strHtml.Replace("<", "");
            strHtml.Replace(">", "");
            strHtml.Replace("\r\n", "");
            strHtml= HttpContext.Current.Server.HtmlEncode(strHtml).Trim();

            return strHtml;
        }


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wuyq11/archive/2009/02/28/3945001.aspx

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载