BBS网站论坛设计参考
为设计BBS网站论坛提供一个参考资料 一个例子:using System; using System.Text; using System.Text.RegularExpressions; namespace doughty_cn.inputcon { /// <summary> /// 转换用户的输入。 /// </summary> public sealed class ConvertString { //将用户输入的字符串转换为可换行、替换Html编码、无危害数据库特殊字符、去掉首尾空白、的安全方便代码。 public static string ConvertStr(string inputString) { string retVal=inputString; retVal=retVal.Replace("&","&"); retVal=retVal.Replace("\"","""); retVal=retVal.Replace("<","<"); retVal=retVal.Replace(">",">"); retVal=retVal.Replace(" "," "); retVal=retVal.Replace(" "," "); retVal=retVal.Replace("\t"," "); retVal=retVal.Replace("\r", "<br>"); return retVal; } public static string OutputText(string inputString) { string retVal=inputString; retVal= ConvertStr(retVal); retVal=retVal.Replace("[url]", ""); retVal=retVal.Replace("[/url]", ""); retVal=retVal.Replace("[img]", ""); retVal=retVal.Replace("[/img]", ""); retVal= Regex.Replace(retVal,@"\[flash=\d+,\d+](?<x>[^\]]*)\[/flash]",@"$1",RegexOptions.IgnoreCase); retVal=retVal.Replace("[flash]", ""); retVal=retVal.Replace("[/flash]", ""); return retVal; } private static string FetchURL( string strMessage) { string strPattern = @"(?<url>(http|ftp|mms|rstp|news|https)://(?:[\w-]+\.)+[\w-]+(?:/[\w-./?%&~=]*[^.\s|,|\)|<|!])?)"; string strReplace = "<a href=\"${url}\" target=_blank>${url}</a>"; string strInput = strMessage; string strResult; strResult = Regex.Replace(strInput, strPattern, strReplace); strPattern = @"(?<!http://)(?<url>www\.(?:[\w-]+\.)+[\w-]+(?:/[\w-./?%&~=]*[^.\s|,|\)|<|!])?)"; strReplace = "<a href=\"http://${url}\" target=_blank>${url}</a>"; strResult = Regex.Replace(strResult, strPattern, strReplace); return strResult; } public static string ToUrl(string inputString) { string retVal=inputString; retVal= ConvertStr(retVal); retVal= FetchURL(retVal); return retVal; } public static string TitleName(string s) { string retVal = System.Configuration.ConfigurationSettings.AppSettings["ForumName1"]; s = s.ToLower().Substring(0,20); int x=s.IndexOf(System.Configuration.ConfigurationSettings.AppSettings["DomainName2"].ToLower()); if (x>=0) { retVal = System.Configuration.ConfigurationSettings.AppSettings["ForumName2"]; } return retVal; } } }
- 1
- 2
- 3
- 粉丝: 0
- 资源: 1
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助