欧美日韩一区二区三区四区不卡,日韩欧美视频一区二区三区四区,久久精品欧美一区二区三区不卡,国产精品久久久乱弄

咨詢電話:186 7916 6165 咨詢電話:186 7916 6165 (微信同號)    在線QQ:181796286
NEWS BLOG ·
學無止境
關注開優網絡 關注前沿
ASP.NET公共類庫之數據壓縮類GZipHandler.cs
ASP.NET公共類庫之客戶端代碼功能類JScript.cs

ASP.NET公共類庫之HTML格式輔助類HtmlUtils.cs

發表日期:2015-09-08    文章編輯:南昌開優網絡    瀏覽次數:3934    標簽:ASP.NET應用

/**********************************************
 * 類作用:   HTML格式輔助類
 * 作者:開優網絡
 * http://www.568387.com
 ***********************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;


namespace Svnhost.Common
{
    public class HtmlUtils
    {

        /// <summary>
        /// 替換回車換行符為html換行符
        /// </summary>
        public static string StrFormat(string str)
        {
            string str2;

            if (str == null)
            {
                str2 = "";
            }
            else
            {
                str = str.Replace("\r\n", "<br />");
                str = str.Replace("\n", "<br />");
                str2 = str;
            }
            return str2;
        }


        public static string GetRealIP()
        {
            string ip = Request.GetIP();

            return ip;
        }

        /// <summary>
        /// 改正sql語句中的轉義字符
        /// </summary>
        public static string mashSQL(string str)
        {
            string str2;

            if (str == null)
            {
                str2 = "";
            }
            else
            {
                str = str.Replace("\'", "'");
                str2 = str;
            }
            return str2;
        }

        /// <summary>
        /// 替換sql語句中的有問題符號
        /// </summary>
        public static string ChkSQL(string str)
        {
            string str2;

            if (str == null)
            {
                str2 = "";
            }
            else
            {
                str = str.Replace("'", "''");
                str2 = str;
            }
            return str2;
        }

       
        /// <summary>
        /// 替換html字符
        /// </summary>
        public static string EncodeHtml(string strHtml)
        {
            if (strHtml != "")
            {
                strHtml = strHtml.Replace(",", "&def");
                strHtml = strHtml.Replace("'", "&dot");
                strHtml = strHtml.Replace(";", "&dec");
                return strHtml;
            }
            return "";
        }
     
       
        /// <summary>
        /// 為腳本替換特殊字符串
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string ReplaceStrToScript(string str)
        {
            str = str.Replace("\\", "\\\\");
            str = str.Replace("'", "\\'");
            str = str.Replace("\"", "\\\"");
            return str;
        }

           
        /// <summary>
        /// 移除Html標記
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public static string RemoveHtml(string content)
        {
            string regexstr = @"<[^>]*>";
            return Regex.Replace(content, regexstr, string.Empty, RegexOptions.IgnoreCase);
        }

        /// <summary>
        /// 過濾HTML中的不安全標簽
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public static string RemoveUnsafeHtml(string content)
        {
            content = Regex.Replace(content, @"(\<|\s+)o([a-z]+\s?=)", "$1$2", RegexOptions.IgnoreCase);
            content = Regex.Replace(content, @"(script|frame|form|meta|behavior|style)([\s|:|>])+", "$1.$2", RegexOptions.IgnoreCase);
            return content;
        }

 
        /// <summary>
        /// 從HTML中獲取文本,保留br,p,img
        /// </summary>
        /// <param name="HTML"></param>
        /// <returns></returns>
        public static string GetTextFromHTML(string HTML)
        {
            System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Regex(@"</?(?!br|/?p|img)[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            return regEx.Replace(HTML, "");
        }      

 
    }
}
主站蜘蛛池模板: 富平县| 仙桃市| 五原县| 辽宁省| 安丘市| 楚雄市| 香河县| 樟树市| 信宜市| 文水县| 珲春市| 西城区| 当雄县| 旅游| 博湖县| 滦南县| 栾川县| 紫云| 绥中县| 镇坪县| 闽侯县| 收藏| 咸阳市| 陕西省| 游戏| 舟曲县| 旌德县| 海兴县| 临朐县| 道真| 河西区| 沂南县| 双峰县| 永宁县| 武胜县| 苍梧县| 马龙县| 卓资县| 泽库县| 肥乡县| 新密市|