|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 ![]() |
|
#2
|
|||
|
|||
|
something like,
Code:
s`((ht|f)tps?:\/\/.+\..+)`<a href=$1 target=new>$1</a>`g; should get it |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Automatically parsing/linking urls |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|