您的位置:首页 > 运维架构 > 网站架构

网站发帖防注入SQL语句之UBB翻译(正则表达式)

2016-09-16 11:19 316 查看
这里借用了一个例子

可以使人更容易理解其原理,运用了正则表达式匹配。

若想放在网站上,普通化即可啦。。。

下面放代码:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Text.RegularExpressions;

using System.Threading.Tasks;

namespace UBB翻译

{

    class Program

    {

        static void Main(string[] args)

        {

            string str = "听说这个论坛是[color=green]其他人[/color]做的.他是百度的";

           string newStr= Regex.Replace(str,@"\[color=(.+)\](.+)\[/color\]", "<font color=\"$1\">$2</font>");

            string msg = Regex.Replace(newStr, @"\[url=(.+)\](.+)\[/url\]的", "<a href=\"$1\">$2</a>的");

            Console.WriteLine(msg);

            Console.ReadKey();

        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐