日期:2014-05-17  浏览次数:20766 次

200分求 处理非法字符的函数
提取文章标题生成html文件,如果标题有特殊字符,比如   ,   :   '   等等,生成时会出现
在   MapPath   方法的路径参数中指定了无效字符   错误提示
忘赐教

------解决方案--------------------
http://www.jb51.net/html/200610/30/2855.htm
------解决方案--------------------
//提取文章标题生成html文件

你看看sina sohu 或者是其他网站,只用随机数生成...
------解决方案--------------------
可以用正则表达式
var str1 = str.match(/[,;]/g);
if( str1 )
{
for( var i=0; i < str1.length; i++)
{
alert( '非法字符: [ ' + str1[i] + '] ')
}
}
------解决方案--------------------
这是vb函数
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches ' 建立变量。
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = True ' 设置是否区分字符大小写。
regEx.Global = True ' 设置全局可用性。
Set Matches = regEx.Execute(strng) ' 执行搜索。
For Each Match in Matches ' 遍历匹配集合。
RetStr = RetStr & "Match found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is ' "
RetStr = RetStr & Match.Value & " '. <p> " & vbCRLF
Next
RegExpTest = RetStr
End Function
Response.Write(RegExpTest( "[,;] ", "select k,d from a;kjf "))
------解决方案--------------------
UP
------解决方案--------------------
用过滤的办法是最笨的!!

最简单的办法是生成时对标题使用escape()函数。

escape的结果符合url的标准,确保不会出现非法字符
而且客户端提交非法字符的请求时,浏览器也会自动使用escape

不过有可能的话用固定长度的编号做html名最好。