Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Extract and modify IMG SRC tags in an HTML document.

by turnstep (Parson)
on Apr 27, 2000 at 01:44 UTC ( #9334=note: print w/ replies, xml ) Need Help??


in reply to Extract and modify IMG SRC tags in an HTML document.

Searching and replacing HTML can be tricky. For example, what about HTML like this:

<H1>Hello World</H1> <IMG HEIGHT="20" WIDTH="20" SRC="me.gif" ALT="My picture!" >
However, if you simply want to replace their picture with yours, use a regexp:
s/SRC="[^"]*"/SRC="$mypicture"/gi;
but you'll also want to remove and/or replace any WIDTH, HEIGHT, and ALT tags as well.

....which get real complicated real quick. Consider using a module to parse the html, or write your own little subroutine to parse each instance of the IMG tag...


Comment on Re: Extract and modify IMG SRC tags in an HTML document.
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://9334]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2014-10-23 01:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (123 votes), past polls