1. asp 过滤字符串中的某些字符
循环读取每一行放在数组里面
s="[00:02.00]歌曲:月半小夜曲"
s=left(s,5)&right(s,len(s)-8)
response.write s
2. 在asp中怎么过滤用户输入的非法字符
<%
dim texts
texts=request("表单明")
dim kill '要过滤的字符
kill="墙,垃,围殴" '比喻
dim rsss
rsss=split(kill,",")
dim i,xxxx,yyyy
for i=0 to ubound(rsss)
xxxx=len(rsss(i))
dim j
for j=1 to xxxx
yyyy=yyyy&"*"
next
dim zzzz '过滤后的字符串
if i=0 then zzzz=texts
'如果你想把过滤字版符换成*
zzzz=replace(zzzz,rsss(i),yyyy)
'如果你想把过滤字符直接去掉
zzzz=replace(zzzz,rsss(i),"")
next
'zzzz就是过权滤后的字符了
%>
3. asp中过滤掉一段字符串
<%
a="44hello456789hello"
a=split(a,"hello")
'以hello为分割符,将a分成多个部分,只取前后两个部分就行了
newa=a(lbound(a))& a(ubound(a))
Response.Write(newa)
%>
楼下的就不对了,
楼主是想把两个过滤符之间的字符串也删掉呢
你那样是只是把过滤符删掉了,如果只是删掉过滤符的话.这样最简单了
newa=replace(a,"hello")
4. 求ASP代码过滤指定字符串
高了半天可以了:
注:.txt里的内容应用“,”分开注意逗号的中英文形式:如下
我爱你,
不和谐,
很和谐
<?php
$fileurl = "123.txt";//txt路径
$objtxt = fopen($fileurl,"r");
$strtxt = fread($objtxt,filesize($fileurl));
echo "要替换的字符:".$strtxt."<br />";
$arrtxt = explode(",",$strtxt); //转成数组;
$str = "这样做是可以的,如果有我爱你,就要被替换了";
echo "替换的字符:".$strtxt."<br />";
$replace = "8888";
echo "把替换字符替换为:".$replace."<br />";
for($i=0;$i<count($arrtxt);$i++){
if(substr_count($str,$arrtxt[$i]) > 0 ){
$str = str_replace($arrtxt[$i],$replace,$str);
}
}
echo "替换后:".$str;
?>
我这里测试成功;有不懂再问。
希望我的回答对你有帮助。
5. 在asp.net传递参数怎么过滤特殊字符
1.传递前先加密 ,KEY是你自己定义的,加密解密函数KEY一致。
public static string Encode(string str, string key)
{
DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
provider.Key = Encoding.ASCII.GetBytes(key.Substring(0, 8));
provider.IV = Encoding.ASCII.GetBytes(key.Substring(0, 8));
byte[] bytes = Encoding.GetEncoding("GB2312").GetBytes(str);
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, provider.CreateEncryptor(), CryptoStreamMode.Write);
stream2.Write(bytes, 0, bytes.Length);
stream2.FlushFinalBlock();
StringBuilder builder = new StringBuilder();
foreach (byte num in stream.ToArray())
{
builder.AppendFormat("{0:X2}", num);
}
stream.Close();
return builder.ToString();
}
2.获取参数后,解密
/// <summary>
/// Des 解密 GB2312
/// </summary>
/// <param name="str">Desc string</param>
/// <param name="key">Key ,必须为8位 </param>
/// <returns></returns>
public static string Decode(string str, string key)
{
try
{
DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
provider.Key = Encoding.ASCII.GetBytes(key.Substring(0, 8));
provider.IV = Encoding.ASCII.GetBytes(key.Substring(0, 8));
byte[] buffer = new byte[str.Length / 2];
for (int i = 0; i < (str.Length / 2); i++)
{
int num2 = Convert.ToInt32(str.Substring(i * 2, 2), 0x10);
buffer[i] = (byte)num2;
}
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, provider.CreateDecryptor(), CryptoStreamMode.Write);
stream2.Write(buffer, 0, buffer.Length);
stream2.FlushFinalBlock();
stream.Close();
return Encoding.GetEncoding("GB2312").GetString(stream.ToArray());
}
catch (Exception)
{
return "";
}
}
6. asp 网站发现有注入漏洞 and 1=2 报错。 请问如何在 asp 的数据库里面过滤这些字符。
SQL注入漏洞一般是通过程序将特殊字符去掉的,基本方法如下:
在将字符串传入SQL语句之前先通过一个函数进行检测,如果其中包含了and、or、update、delete等信息,则报错。
在数据库的命名规则中要进行一些前缀处理,不要用通常的命名规则去命名表和字段,比如用户表,不用users或者tbusers,而是采取esc_tbusers,这样在一定程度上也能防止SQL注入的问题。
7. asp 过滤字符串问题
嗯嗯,我有办法。送你一个过滤函数(仅保留<br>标签)。
<%
function filterhtml(byval fstring)
if isnull(fstring) or trim(fstring)="" then
filterhtml=""
exit function
end if
fstring = replace(fstring, "
", "[br]")
fstring = replace(fstring, "
", "[br]")
'过滤html标签
dim re
set re = new regexp
re.ignorecase=true
re.global=true
re.pattern="<(.+?)>"
fstring = re.replace(fstring, "")
set re=nothing
fstring = replace(fstring, "[br]", "
")
filterhtml = fstring
end function
%>
8. ASP字符过滤。
username=trim(request.form("username"))
'定义一个数组
badCode="<,%,@,upload"
'分割数据
badCode=split(badCode,",")
'从第一个循环到最后一个
for i = 0 to ubound(badCode)
username=replace(username,badCode(i),"") '把这专些字符替换属为空
next