URI::Find to ignore images

J

Jason Carlton

I'm using URI::Find to convert addresses to links, like so:

$finder = URI::Find -> new(
sub {
($uri, $orig_uri) = @_;
return "<a href='$uri'>orig_uri</a>";
}
);

$finder -> find(\$text);


Is there a way to make this ignore images, so that it doesn't create:

<img src="<a href="http://www.whatever.com/image.jpg">http://
www.whatever.com/image.jpg</a>">

The images on my server will have several different path
possibilities, so there's nothing constant inside of $uri to scan for.

I thought about letting it do this, then manually manipulating $text,
but there has to be a better way! Something like:

while ($text =~ /(<img[^>]+?>)/sgxi) {
$mod_text = $1;
$mod_text =~ s/<a href="//gi;
$mod_text =~ s/<\/a>//gi;
}

I haven't tried that, but it seems like it would work, although it
leaves a LOT of room for error.

TIA,

Jason
 
J

Jürgen Exner

Jason Carlton said:
I'm using URI::Find to convert addresses to links, like so:

In your terminology what do you call an address and what do you call a
link?
$finder = URI::Find -> new(
sub {
($uri, $orig_uri) = @_;
return "<a href='$uri'>orig_uri</a>";

In Perl terms the return value is a string.
In HTML terms the return value is an anchor tag.

Now, where are the address and the link?
Is there a way to make this ignore images, so that it doesn't create:

I guess you could try to match against the set of jpg, gif, bmp, .....

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top