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