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

咨詢電話:186 7916 6165 咨詢電話:186 7916 6165 (微信同號)    在線QQ:181796286
NEWS BLOG ·
學(xué)無止境
關(guān)注開優(yōu)網(wǎng)絡(luò) 關(guān)注前沿
ASP.NET公共類庫之?dāng)?shù)據(jù)壓縮類GZipHandler.cs
ASP.NET公共類庫之客戶端代碼功能類JScript.cs

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

發(fā)表日期:2015-09-08    文章編輯:南昌開優(yōu)網(wǎng)絡(luò)    瀏覽次數(shù):3971    標(biāo)簽:ASP.NET應(yīng)用

/**********************************************
 * 類作用:   HTML格式輔助類
 * 作者:開優(yōu)網(wǎng)絡(luò)
 * 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語句中的轉(zhuǎn)義字符
        /// </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標(biāo)記
        /// </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中的不安全標(biāo)簽
        /// </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, "");
        }      

 
    }
}
主站蜘蛛池模板: 浮山县| 龙泉市| 东辽县| 千阳县| 旬阳县| 萨迦县| 涿鹿县| 无为县| 成安县| 天水市| 城口县| 大渡口区| 土默特左旗| 绍兴县| 商都县| 措勤县| 泸州市| 博野县| 凯里市| 日照市| 玉田县| 双桥区| 尼木县| 武宁县| 双柏县| 淄博市| 云南省| 肇州县| 驻马店市| 虎林市| 马公市| 女性| 台东市| 图片| 渭源县| 抚宁县| 尼勒克县| 奎屯市| 黑水县| 浠水县| 顺义区|