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

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.