此函數可以將html代碼裡的所有圖片路徑讀取出來,這樣就可以將批量擷取的圖片路徑儲存到資料庫,或者批量將圖片打上浮水印,或者批量進行圖片縮減,想怎麼操作就怎麼操作,這樣就很方便了。
如果路徑是http://開頭的,您還可以使用遠程下載檔案的函數進行下載。這樣就做到了批量下載HTML代碼時的遠程圖片或者檔案了。
Function oflink_lcasetag(imgstrng)
'非凡設計原創361du.net
'將內容html代碼裡的標籤大寫轉換成小寫
Dim regEx, Match, Matches '建立變數。
Set regEx = New RegExp '建立Regex。
regEx.Pattern = "<.+?\>" '設定模式。
regEx.IgnoreCase = true '設定是否區分字元大小寫。
regEx.Global = True '設定全域可用性。
Set Matches = regEx.Execute(imgstrng) '執行搜尋。
imgstrng=imgstrng
For Each Match in Matches '遍曆匹配集合。
imgstrng=replace(imgstrng,Match.Value,lcase(Match.Value))
Next
oflink_lcasetag = imgstrng
End Function
Function ofink_getsrc(strng)
'非凡設計原創361du.net
'批量擷取圖片路徑
strng=oflink_lcasetag(strng)
Dim regEx, Match, Matches,values,if_add '建立變數。
Set regEx = New RegExp '建立Regex。
regEx.Pattern = "src\=.+?\.(gif|jpg|jpeg|jpe|png)"
regEx.IgnoreCase = true '設定是否區分字元大小寫。
regEx.Global = True '設定全域可用性。
Set Matches = regEx.Execute(strng) '執行搜尋。
if_add=0
For Each Match in Matches '遍曆匹配集合。
values=values&Match.Value&"|"
if_add=1
Next
values=replace(values,"src=""","")
values=replace(values,"src='","")
values=replace(values,"src=","")
if if_add=1 then values=left(values,len(values)-1)
ofink_getsrc = values
End Function
此函數使用方法:imglist=ofink_getsrc(content)
其中content可以是編輯框中包含多張圖片的內容
imglist的結果就是將每個圖片用"|"隔開,如:1.jpg|2.jpg|3.jpg
得到這個結果後就可以使用split函數擷取單個圖片,要對這些圖片做什麼操作就自己想了。