Use regular expressions to implement image news. asp

Source: Internet
Author: User

'Display news in text or specific image mode

Function shownew (content, ntype)

Shownew = ""

If (ntype = 1) then

Shownew = shownew & "<Table width = 100%>"
Shownew = shownew & "<tr>"
Shownew = shownew & "<TD width = 600 style = 'word-break: Break-All 'valign = top>" & showpic (content) & "</TD>"
Shownew = shownew & "</tr>"
Shownew = shownew & "<tr>"
Shownew = shownew & "<TD valign = top style = 'word-break: Break-all'>" & onlyword (content) & "</TD>"
Shownew = shownew & "</tr>"
Shownew = shownew & "</table>"

Elseif (ntype = 2) then

Shownew = shownew & "<Table width = '000000'>"

Shownew = shownew & "<tr>"
Shownew = shownew & "<TD style = 'word-break: Break-all' valign = top>" & onlyword (content) & "</TD>"
Shownew = shownew & "</tr>"
Shownew = shownew & "<tr>"
Shownew = shownew & "<TD width = 600 valign = top style = 'word-break: Break-all'>" & showpic (content) & "</TD>"
Shownew = shownew & "</tr>"
Shownew = shownew & "</table>"

Elseif (ntype = 3) then

Shownew = shownew & "<Table>"

Shownew = shownew & "<tr>"
Shownew = shownew & "<TD width = 100 valign = top>" & showpic (content) & "</TD>"

Shownew = shownew & "<TD width = 80% style = 'word-break: Break-All 'valign = top>" & onlyword (content) & "</TD>"

Shownew = shownew & "</tr>"
Shownew = shownew & "</table>"

Elseif (ntype = 4) then

Shownew = shownew & "<Table>"

Shownew = shownew & "<tr>"

Shownew = shownew & "<TD width = 80% valign = top style = 'word-break: Break-all'>" & onlyword (content) & "</TD>"
Shownew = shownew & "<TD width = 100 valign = top>" & showpic (content) & "</TD>"

Shownew = shownew & "</tr>"
Shownew = shownew & "</table>"
Else
Shownew = shownew & "<Table> <tr> <TD style = 'word-break: break-all'> "& content &" </TD> </tr> </table>"
End if

End Function

'Show extracted Images
Function showpic (strng)

Showpic = ""
Imageurl = regexpexecute (strng)

Imageurls = Split (imageurl, "<br> ")

For I = lbound (imageurls) to (ubound (imageurls)-1)

Showpic = showpic & ("<a href = '" & imageurls (I) & "'target = _ blank> <image src ='" & imageurls (I) & "'border = '0' alt = 'click here to browse the image in the new window 'onload = 'javascript: If (this. width> 180) This. width = 180 '> </a> ")

Next
 
End Function

'Extract the image from the content
Function regexpexecute (strng)
Dim RegEx, match, matches 'to create a variable.
Set RegEx = new Regexp 'to create a regular expression.
RegEx. pattern = "(src =) ('|" & CHR (34) & "| )? (. [^ '|/S | "& CHR (34) &"] *) (/.) (JPG | GIF | PNG | BMP | JPEG) ('| "& CHR (34) &" |/S |> )? "'Setting mode.
'Regex. pattern = "(src =) ('|" & CHR (34) & "| )? (. [^ '| "& CHR (34) &"] *) (/.) (JPG | GIF | PNG | BMP | JPEG) ('| "& CHR (34) &" |> )? "'Setting mode.
'Regex. pattern = "(S | S) (R | r) (C | C) = ('|" + CHR (34) + ") (/w | // | /.) + ('| "+ CHR (34) +" | * |> )? "'Setting mode.
RegEx. ignorecase = true' specifies whether the characters are case sensitive.
RegEx. Global = true' to set global availability.
Set matches = RegEx. Execute (strng) 'to execute the search.
For each match in matches 'traverses the matching set.
Values = Values & Match. submatches (2) & Match. submatches (3) & Match. submatches (4) & "<br>"
Next
Regexpexecute = values
End Function

'Delete the image-related code in the content.
Function onlyword (strng)
Set Re = new Regexp
Re. ignorecase = true
Re. Global = true

Re. pattern = "(<) (. [^ <] *) (src =) ('|" & CHR (34) & "| )? (. [^ '|/S | "& CHR (34) &"] *) (/.) (JPG | GIF | PNG | BMP | JPEG) ('| "& CHR (34) &" |/S |> )(. [^>] *) (>) "'setting mode.
Onlyword = Re. Replace (strng ,"")
Set Re = nothing

End Function

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.