Solved

link parser

Posted on 2004-10-22
226 Views
Last Modified: 2008-03-06
hello,
I need some code that will parse some text and change all the URLs to clickable links.  The qystem will be very simular to EE's:

examples that it needs to identify:

http://www.google.com
http://google.com
www.google.com

The script will also need to change links that are for the site into links also.  Example:

http:help.html
http://help.html

http:Q_10000000.html
http://Q_10000000.html

http:#10000000
http://#10000000

all the numbers will be 8 digits long, if that is needed for the script.  The problem I have had with other scripts is that the script puts a / after the URL for the "special" URLs (the last ones listed).  I assume this would only require a slight modification to any of the numerious link parsing scripts out there.

Thanks!
Matt
0
Question by:mattjp88
    6 Comments
     
    LVL 8

    Expert Comment

    by:sigmacon
    Please post one of the scripts that came the closest to what you wanted to do, and then we can tinker with it.
    0
     
    LVL 6

    Author Comment

    by:mattjp88
    sorry, I just got thinking and playing, and got it to work.  woo hoo!

    requesting delete.

    Thanks!
    0
     
    LVL 8

    Expert Comment

    by:sigmacon
    delete / refund is fine
    0
     
    LVL 3

    Expert Comment

    by:andYetAnotherLoginName
    no, no, I object. Let us see the solution :)
    0
     
    LVL 8

    Expert Comment

    by:sigmacon
    OK, YOU MUST SHOW THE SOLUTION, OR WE WILL FIND YOU AND GET IT FROM YOU - AND GIVE MY POINTS - WAH HA HA HA HA ... no, seriously, I don't care.
    0
     
    LVL 6

    Accepted Solution

    by:
    >Mod
    PAQ/Refund please....

    the solution:

    function linkParser($str) {

      $str = eregi_replace("([[:space:]])((f|ht)tps?:\/\/[a-z0-9~#%@\&:=?+\/\.,_-]+[a-z0-9~#%@\&=?+\/_-]+)", "\\1<a href=\"\\2\">\\2</a>", $str); //http
      $str = eregi_replace("([[:space:]])(www\.[a-z0-9~#%@\&:=?+\/\.,_-]+[a-z0-9~#%@\&=?+\/_-]+)", "\\1<a href=\"http://\\2\">\\2</a>", $str); // www.
     
      $str = eregi_replace("^((f|ht)tp:\/\/[a-z0-9~#%@\&:=?+\/\.,_-]+[a-z0-9~#%@\&=?+\/_-]+)", "<a href=\"\\1\">\\1</a>", $str); //http
      $str = eregi_replace("^(www\.[a-z0-9~#%@\&:=?+\/\.,_-]+[a-z0-9~#%@\&=?+\/_-]+)", "<a href=\"http://\\1\">\\1</a>", $str); // www.

      $str = eregi_replace("([[:space:]])(http:[a-z0-9~#%@&:=?/\+.,_-]+[a-z0-9~#%@&=?/\+_-]+)", "<a href=\"\\2\">\\2</a>", $str); //local links
     
      return $str;
    }
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    The Complete Ruby on Rails Developer Course

    Ruby on Rails is one of the most popular web development frameworks, and a useful tool used by both startups and more established companies to build strong graphic user interfaces, and responsive websites and apps.

    Suggested Solutions

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now