There are still bugs, the latest test page in: http://www.reallydo.com/getimg.asp
Regular Analysis page in: http://jorkin.reallydo.com/article.asp?id=380
Find the bug please leave a message behind, thank you.
1.31 Amendment
There are spaces behind the src= that do not match correctly. Modified.
Error src= ' is empty. Modified.
Bug found: A picture path can have more than one space. Not fixed.
2.18 Amendment
A picture path can have more than one space in it. has been fixed.
<%
' Function: Get all picture addresses, save to an array.
' Source: http://jorkin.reallydo.com/article.asp?id=448
' Need ReplaceAll function: http://jorkin.reallydo.com/article.asp?id=406
Function getimg (sstring)
Dim Sreallydo, RegEx, Ireallydo
Dim omatches, Cmatch
//define an empty Array
Ireallydo =-1
ReDim areallydo (ireallydo)
If IsNull (sstring) Then
getimg = Areallydo
Exit Function
End If
'//Format HTML code
'// &NBSP ; Sreallydo = sstring
on Error Resume Next
Sreallydo = Replace (Sreallydo, vbcr, "")
Sreall Ydo = replace (Sreallydo, vblf, "")
Sreallydo = replace (Sreallydo, VbTab, "")
Sreallydo = replace (s Reallydo, " Sreallydo = Replace (Sreallydo, "/>", "/>", 1,- 1, 1)
Sreallydo = ReplaceAll (Sreallydo, "=", "=", True)
Sreallydo = ReplaceAll (Sreallydo, ">", ">, True"
Sreallydo = Replace (Sreallydo, "><", ">" & vbCrLf & "<")
Sreallydo = Trim (Sreallydo)
Set regEx = New RegExp
Regex.ignorecase = True
Regex.global = True
'//Remove Onclick,o Scripts such as nload
Regex.pattern = "s[on].+?= ([" "|]) (.*?) 1 "
Sreallydo = Regex.Replace (Sreallydo," ")
'//Add quotes to the picture address of Src not quoted
Regex.pattern =" <im g.*?ssrc= ([^ "" ' s][^ "" ' s>]*) .*?> "
Sreallydo = Regex.Replace (Sreallydo," ")
//Regular matching picture src address
http://bizhi.cncms.com/
Regex.pattern = " "
Set omatches = Regex.execute (sreallydo)
"//Save picture Address to array
for each cmatch in Omatche s
Ireallydo = ireallydo + 1
ReDim PReserve areallydo (ireallydo)
Areallydo (ireallydo) = RE Gex.replace (Cmatch.value, "$")
Next
getimg = Areallydo
End Function
%>
<%
' usage: A lot of people ask me how to use, in fact, how to use the array how to use this.
scontent = "HTML code field"//scontent represents the HTML code, originally write a ors how do not know is the recordset ...
Dim aimages:aimages = getimg (scontent) '//define an array and use it to store all the parsed picture addresses
' lists all of the pictures ' addresses:
for i = 0 to UBound (aimages) br> Response.Write ("<b> First" & i + 1 & "Picture address:</b>" & Aimages (i) & "<br/>")
Ne XT
' list first picture address:
If UBound (aimages) >-1 Then Response.Write ("<p><b> First picture address:</b>" & Aimages (0) & "</p>")
' list last picture address:
If UBound (aimages) >-1 Then Response.Write ("<p><b> Last picture Address:</b> "& Aimages (UBound (aimages)) &" </p> "
%>