Url search - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Url search

I am programming a forum, and have a wall. I would like to check if a paragraph of text has a url with in it. Then surround that url with a link tag. For example:


http://www.urlhere.com



would then become


http://www.urlhere.com


Boycey


Comments

  • I am assuming you have already got the paragraph into

    a scalar variable.


    $bufftext = $paragraph;


    # Get rid of


    chomp($bufftext);


    # Split words at spaces

    @words = split(" ", $bufftext);


    # Skim through words looking for URLS


    foreach $word (@words) {

    # if word is url format

    if($word =~ /http://.*..*/) {

    print "$word";

    }

    else {

    print "$word";

    }


    Hope this helps,

    Matt(AA)


    : I am programming a forum, and have a wall. I would like to check if a paragraph of text has a url with in it. Then surround that url with a link tag. For example:


    : http://www.urlhere.com

    :

    : would then become


    : http://www.urlhere.com


    : Boycey





Sign In or Register to comment.