URI::Find to ignore images

Discussion in 'Perl Misc' started by Jason Carlton, Nov 30, 2009.

  1. 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
    Jason Carlton, Nov 30, 2009
    #1
    1. Advertising

  2. Jason Carlton <> wrote:
    >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
    Jürgen Exner, Nov 30, 2009
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon Harris
    Replies:
    0
    Views:
    6,352
    Simon Harris
    May 10, 2005
  2. Stanimir Stamenkov
    Replies:
    1
    Views:
    2,455
    Stanimir Stamenkov
    Aug 17, 2005
  3. Pavel
    Replies:
    2
    Views:
    1,627
    Peter Flynn
    Aug 4, 2004
  4. etheriau
    Replies:
    1
    Views:
    662
    Pavel
    Aug 23, 2004
  5. Joe Curry

    Invalid URI: The format of the URI could not be determined.

    Joe Curry, Oct 8, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    331
    Joe Curry
    Oct 8, 2003
Loading...

Share This Page