[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

link parser

Posted on 2004-10-22
8
Medium Priority
?
236 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
Comment
Question by:mattjp88
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:sigmacon
ID: 12386783
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
ID: 12386785
sorry, I just got thinking and playing, and got it to work.  woo hoo!

requesting delete.

Thanks!
0
 
LVL 8

Expert Comment

by:sigmacon
ID: 12386867
delete / refund is fine
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 3

Expert Comment

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

Expert Comment

by:sigmacon
ID: 12402194
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:
mattjp88 earned 0 total points
ID: 12403432
>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

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

612 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