導航:首頁 > 凈水問答 > sql過濾html

sql過濾html

發布時間:2021-01-19 21:45:10

『壹』 sql只讀表中的文字不讀html標簽中的東西例如(<font>asdsad</font>這些內容不讀)

需要自己寫過濾判斷,提示:標簽共有特徵是"<"或">",你可以以文件流的方式讀取整個文件,然後再截取標簽,剩下的就是內容了!

『貳』 如何讀取sql server資料庫中的html代碼

HTML是無法讀取資料庫的,HTML是頁面前端腳本語言,要想從網頁中獲取SQL資料庫里的數據,需要藉助JSP或ASP或PHP或RUBY等語言來實現。 簡單的關系可以這樣理解: 資料庫<--->JSP或ASP或PHP或RUBY等語言<--->HTML
如:在JSP頁面中顯示完整代碼如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

<%@ page
language="java"
contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"
%>
<%@page import="java.sql.*"%>
<center>
<H1> <font color="blue" size="12">管理中心</font></H1>
<HR />
<table width="80%" border="1">
<tr>
<th>ID</th>
<th>書名</th>
<th>作者</th>
<th>價格</th>
<th>刪除</th>
</tr>
<%
// 資料庫的名字
String dbName = "zap";
// 登錄資料庫的用戶名
String username = "sa";
// 登錄資料庫的密碼
String password = "123";
// 資料庫的IP地址,本機可以用 localhost 或者 127.0.0.1
String host = "127.0.0.1";
// 資料庫的埠,一般不會修改,默認為1433
int port = 1433;
String connectionUrl = "jdbc:sqlserver://" + host + ":" + port + ";databaseName=" + dbName + ";user=" + username
+ ";password=" + password;
//
//聲明需要使用的資源
// 資料庫連接,記得用完了一定要關閉
Connection con = null;
// Statement 記得用完了一定要關閉
Statement stmt = null;
// 結果集,記得用完了一定要關閉
ResultSet rs = null;
try {
// 注冊驅動
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// 獲得一個資料庫連接
con = DriverManager.getConnection(connectionUrl);
String SQL = "SELECT * from note";
// 創建查詢
stmt = con.createStatement();
// 執行查詢,拿到結果集
rs = stmt.executeQuery(SQL);
while (rs.next()) {
%>
<tr>
<td>
<%=rs.getInt(1)%>
</td>
<td>
<a href="prepareupdate?ID=<%=rs.getInt("ID")%>" target="_blank"><%=rs.getString(2)%></a>
</td>
<td>
<%=rs.getString(3)%>
</td>
<td>
<%=rs.getString(4)%>
</td>
<td>
<a href="delete?ID=<%=rs.getInt("ID")%>" target="_blank">刪除</a>
</td>
</tr>
<%
}
} catch (Exception e) {
// 捕獲並顯示異常
e.printStackTrace();
} finally {
// 關閉我們使用過的資源
if (rs != null)
try {
rs.close();
} catch (Exception e) {}
if (stmt != null)
try {
stmt.close();
} catch (Exception e) {}
if (con != null)
try {
con.close();
} catch (Exception e) {}
}
%>
</table>
<a href="insert.jsp">添加新紀錄</a>
</center>

『叄』 如何向sql資料庫存儲一段帶有html標記的文字

insert into table(column)
select '<a href="index.html">home</a>'--字元串裡面是帶雙引號的

insert into table(column)
select '<a href=''index.html''>home</a>'--字元串裡面是帶單引號的

兩個,一,帶雙引號的,按照字元串的方式內插容入就好
二、帶單引號的,在sql中兩個單引號表示字元串裡面的單引號

『肆』 怎樣把SQL中的數據輸出到HTML頁面

平常在查詢資料庫的時候,經常會把一些查詢的結果保存起來,如數據存放到EXCEL中,但如果能有辦法把數據存放到HTML頁面中去顯示,並且把數據以網頁形式展現出來的時候,這樣會更直觀。
先來了解一下模板文件,Template模板,後綴名稱為TPL,TPL文件和HTML文件一樣,在TPL文件中注意其中的<%begindetail%><%enddetail%>"<%insert_data_here%>標記,分別代表的意思如下:
Begindetail:代表准備開始替換模板文件的開始
Enddetail:代表結束替換模板文件
insert_data_here:代表指明在何處插入結果集中的數據。如果結果集記錄中包含多個欄位的話,insert_data_here將按照其在記錄中的順序,也就是查詢語句SELECT執行語句中的欄位順序,來按順序地插入數據。也就是說,每個結果記錄中的每個欄位只能在頁面中被插入一次。如果要想在頁面中多次使用某個欄位,可以先將它賦給一個變數。然後再反復地使用此變數即可。
那就來做一個簡單格式的TPL模板,命名為OutPutHtml.TPL,模板的HTML代碼如下:
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /
<TITLEshow HTML</TITLE<BODY<center<P<H2<TABLE BORDER="1" cellpadding="0" cellspacing="0"
<TR <TH<B公司名稱</B</TH
<TH<B聯系人</B</TH
<TH<B產品名稱</B</TH
<TH<B產品名稱</B</TH</TR<%begindetail%
<TR <TD <%insert_data_here% </TD
<TD ALIGN=RIGHT<%insert_data_here%</TD
<TD ALIGN=RIGHT<%insert_data_here%</TD</TR<%enddetail%</TABLE</center</H2</BODY</HTML模板文件做好後,先把它存放在「D:\SQL Server文件」目錄下面

『伍』 SQL欄位內容含有HTML標簽,如何模糊查詢

代碼是在VC++裡面:

[cpp] view plainprint?
CString sql, str;
sql.Format(_T("SELECT * FROM tbPatient WHERE admitDate BETWEEN CDate('%s %s') AND CDate('%s %s')"),
dtStartDate.Format(_T("%x")), dtStartTime.Format(_T("%X")),
dtEndDate.Format(_T("%x")), dtEndTime.Format(_T("%X")));

//欄位合並的模糊查詢 MYSQL concat(email,address) like 'like%df%'
if(!strKeyWord.IsEmpty())
{
//SQL Server中IsNull(expression, replace)有替換功能,
//Access需要結合IsNull ( expression ), iif (condition, value_if_true, value_if_false )函數

//str.Format(_T(" AND IsNull(name, ' ') & IsNull(Empid, ' ') LIKE '%%%s%%'"),
// strKeyWord.GetBuffer(0));

str.Format(_T(" AND iif(IsNull(name),' ',name) & iif(IsNull(Empid),' ',Empid) LIKE '%%%s%%'"),
strKeyWord.GetBuffer(0));

sql += str;
}

TRACE1("%s\n", sql);

『陸』 有沒有sql語句可以刪除某個欄位中的某些html代碼

1、SQL語句暫時沒有這樣的處理方法
2、不過可以使用自定義函數+DLL的方式,思路如下版
1)、使用權.net編寫DLL,裡面需要有正則表達式的替換方法

2)、然後在SQL資料庫中注冊這個DLL

3)、編寫一個自定義函數,用於剔除HTML代碼

『柒』 求助 SQL語句 過濾HTML代碼

<%Function htmlDecode(strHTML)
Dim objRegExp, Match, Matches
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
'取閉合的<>
objRegExp.Pattern = "<.+?>"
'進行匹配
Set Matches = objRegExp.Execute(strHTML)
' 遍歷匹配集合,並替換掉匹配的項專目
For Each Match in Matches
strHtml=Replace(strHTML,Match.Value,"")
Next
htmlDecode=strHTML
Set objRegExp = Nothing
End Function
%>

調用屬函數

『捌』 如何在SQL語句中清除HTML標簽

<%
db="data.mdb"
set conn=server.createobject("Adodb.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath(db)
conn.open connstr
set rs=server.createobject("adodb.recordset")
sql="select * from 表"
rs.open sql,conn,1,3
do while rs.eof=false
rs("欄位一")=Html2Ubb(rs("欄位一")) '在這里使用Html2Ubb函數將欄位的數據轉換成純文本形式後寫入資料庫
rs("欄位二")=Html2Ubb(rs("欄位二"))
rs("欄位三")=Html2Ubb(rs("欄位二"))
rs.update
rs.movenext
loop
rs.close
set rs=nothing
conn.close
set conn=nothing

Public Function Html2Ubb(ByVal strContent)
On Error Resume Next
If Len(strContent) > 0 Then
Dim re
Set re = New RegExp

re.IgnoreCase = True
re.Global = True
'--清除script腳本
If CInt(ArrayCodes(0)) = 1 Then
re.Pattern = "(<s+cript(.+?)<\/s+cript>)"
strContent = re.Replace(strContent, "")
End If
'--清除所有iframe框架
If CInt(ArrayCodes(1)) = 1 Then
re.Pattern = "(<iframe(.+?)<\/iframe>)"
strContent = re.Replace(strContent, "")
End If
'--清除所有object對象
If CInt(ArrayCodes(2)) = 1 Then
re.Pattern = "(<object(.+?)<\/object>)"
strContent = re.Replace(strContent, "")
End If
'--清除所有java applet
If CInt(ArrayCodes(3)) = 1 Then
re.Pattern = "(<applet(.+?)<\/applet>)"
strContent = re.Replace(strContent, "")
End If
'--清除所有div標簽
If CInt(ArrayCodes(4)) = 1 Then
re.Pattern = "(<DIV>)|(<DIV(.+?)>)"
strContent = re.Replace(strContent, "")
re.Pattern = "(<\/DIV>)"
strContent = re.Replace(strContent, "")
End If
'--清除所有font標簽
If CInt(ArrayCodes(5)) = 1 Then
re.Pattern = "(<FONT>)|(<FONT(.+?)>)"
strContent = re.Replace(strContent, "")
re.Pattern = "(<\/FONT>)"
strContent = re.Replace(strContent, "")
End If
'--清除所有span標簽
If CInt(ArrayCodes(6)) = 1 Then
re.Pattern = "(<SPAN>)|(<SPAN(.+?)>)"
strContent = re.Replace(strContent, "")
re.Pattern = "(<\/SPAN>)"
strContent = re.Replace(strContent, "")
End If
'--清除所有A標簽
' If CInt(ArrayCodes(7)) = 1 Then
re.Pattern = "(<A>)|(<A(.+?)>)"
strContent = re.Replace(strContent, "")
re.Pattern = "(<\/A>)"
strContent = re.Replace(strContent, "")
' End If
'--清除所有img標簽
If CInt(ArrayCodes(8)) = 1 Then
re.Pattern = "(<IMG(.+?)>)"
strContent = re.Replace(strContent, "")
End If
'--清除所有FORM標簽
If CInt(ArrayCodes(9)) = 1 Then
re.Pattern = "(<FORM>)|(<FORM(.+?)>)"
strContent = re.Replace(strContent, "")
re.Pattern = "(<\/FORM>)"
strContent = re.Replace(strContent, "")
End If
'--清除所有HTML標簽
If CInt(ArrayCodes(10)) = 1 Then
re.Pattern = "<(.[^>]*)>"
strContent = re.Replace(strContent, "")
End If
re.Pattern = "(" & Chr(8) & "|" & Chr(9) & "|" & Chr(10) & "|" & Chr(13) & ")"
strContent = re.Replace(strContent, vbNullString)
re.Pattern = "(<!--(.+?)-->)"
strContent = re.Replace(strContent, vbNullString)
re.Pattern = "(<TBODY>)"
strContent = re.Replace(strContent, "")
re.Pattern = "(<\/TBODY>)"
strContent = re.Replace(strContent, "")
re.Pattern = "(<" & Chr(37) & ")"
strContent = re.Replace(strContent, "<%")
re.Pattern = "(" & Chr(37) & ">)"
strContent = re.Replace(strContent, "%>")
Set re = Nothing
Html2Ubb = strContent
Else
Html2Ubb = ""
End If
Exit Function
End Function
%>

『玖』 SQL欄位內容含有HTML標簽,如何模糊查詢

代碼是在VC++裡面:
[cpp]
view
plainprint?
CString
sql,
str;
sql.Format(_T("SELECT
*
FROM
tbPatient
WHERE
admitDate
BETWEEN
CDate('%s
%s')
AND
CDate('%s
%s')"),
dtStartDate.Format(_T("%x")),
dtStartTime.Format(_T("%X")),
dtEndDate.Format(_T("%x")),
dtEndTime.Format(_T("%X")));
//欄位合並的模糊查詢
MYSQL
concat(email,address)
like
'like%df%'
if(!strKeyWord.IsEmpty())
{
//SQL
Server中IsNull(expression,
replace)有替換功能,
//Access需要結合IsNull
(
expression
),
iif
(condition,
value_if_true,
value_if_false
)函數
//str.Format(_T("
AND
IsNull(name,
'
')
&
IsNull(Empid,
'
')
LIKE
'%%%s%%'"),
//
strKeyWord.GetBuffer(0));
str.Format(_T("
AND
iif(IsNull(name),'
',name)
&
iif(IsNull(Empid),'
',Empid)
LIKE
'%%%s%%'"),
strKeyWord.GetBuffer(0));
sql
+=
str;
}
TRACE1("%s\n",
sql);

『拾』 [問]如何在sql查詢的時候過濾HTML

有點困難,要進行資料庫編程,如果是用MSSQL資料庫比較好解決。

閱讀全文

與sql過濾html相關的資料

熱點內容
排污溝的廢水產生什麼氣體 瀏覽:393
長沙國慮水處理 瀏覽:384
賣機油濾芯屬於什麼經營范圍 瀏覽:541
污水提升泵是裝在里嗎 瀏覽:412
樹脂鏡片能摔爛嗎 瀏覽:769
發現者5用什麼空氣凈化器 瀏覽:596
臭氧焦化廢水 瀏覽:196
富濾機油濾芯怎麼檢測 瀏覽:685
快捷方便高水質反滲透純水系統 瀏覽:203
離子交換層析分離酸性蛋白質 瀏覽:790
宜興一體化污水設備廠家 瀏覽:701
蔬菜清洗廢水處理 瀏覽:336
美的nm空氣凈化器怎麼設置 瀏覽:585
污水井砼澆築多少錢一米 瀏覽:271
無機離子讓樹脂沉降 瀏覽:400
樹脂吸附硫酸軟骨素中檸檬酸 瀏覽:26
南充污水泵站哪裡好 瀏覽:251
凈水器為什麼加白醋 瀏覽:499
怎樣提升路由器信號強度 瀏覽:303
水產養殖水處理圖片 瀏覽:787