ASP使用Regex批量分離編輯框中的圖片從而擷取圖片路徑

來源:互聯網
上載者:User

此函數可以將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函數擷取單個圖片,要對這些圖片做什麼操作就自己想了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.