link parser

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
LVL 6
mattjp88Asked:
Who is Participating?
 
mattjp88Author Commented:
>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
 
sigmaconCommented:
Please post one of the scripts that came the closest to what you wanted to do, and then we can tinker with it.
0
 
mattjp88Author Commented:
sorry, I just got thinking and playing, and got it to work.  woo hoo!

requesting delete.

Thanks!
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
sigmaconCommented:
delete / refund is fine
0
 
andYetAnotherLoginNameCommented:
no, no, I object. Let us see the solution :)
0
 
sigmaconCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.