Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 30th, 2001, 05:37 AM
NetAmp NetAmp is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: Netherlands
Posts: 5 NetAmp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question

Hi there, I run a simple forum on a site, and I'd like URLs
in a message to be automatically replaced with something
like this when it's posted:
<a href="theurl" target="_blank">theurl</a>

I'm kinda new to regular expressions and I haven't
found a solution to this one yet.
Thanx for any help

Reply With Quote
  #2  
Old March 30th, 2001, 07:58 AM
ssert ssert is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Posts: 17 ssert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 40 sec
Reputation Power: 0
something like,
Code:
s`((ht|f)tps?:\/\/.+\..+)`<a href=$1 target=new>$1</a>`g;

should get it

Reply With Quote
  #3  
Old March 30th, 2001, 12:40 PM
NetAmp NetAmp is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: Netherlands
Posts: 5 NetAmp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks!

Thanks for the code

It doesn't seem to work OK when there are more than
one URLs in the message though...

But I got the right code from you now and I'll post it
here so maybe others can use it too:
s!((ht|f)tps?://[a-zA-Z0-9_\.?&=/%\+\;:~-]+)!<a href=\"$1\" target=\"_blank\">$1</a>!g

Reply With Quote
  #4  
Old March 30th, 2001, 04:29 PM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 10
Heh
Code:
use CGI qw/:standard/;

$var =~ s|(ht|f)tps?://(\S+)|a({-href=>$2, -target=>'_blank'}, $2)|ige;

I just used CGI.pm so the link part would look cleaner. In fact, I've never evn tried to use this code. I'm sure it'll work though.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Automatically parsing/linking urls


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT