Thread Email::Find und E-Mails in Links?
(14 answers)
Opened by bianca at 2010-06-01 16:22
Also so:
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 #--------# sub identifylinks { # # Erkennt und markiert Hyperlinks in einem Text # # Aufruf: # ======= # my $testtext = 'test: http://www.test.de'; # identifylinks (\$testtext,'<a href="%s" target="_blank">%s</a>','<a href="mailto:%s">%s</a>'); # print $testtext; # my $text = $_[0]; my $link = $_[1]; my $email_link = (defined $_[2] ? $_[2] : ''); if(eval "use URI::Find; 1;") { my $finder = URI::Find -> new ( sub { return sprintf ($link,@_); } ); my $call=sub{ return $_[0]; }; if($email_link ne '' && eval "use Email::Find; 1;" ) # E-Mail auch erwünscht? { my $finder = Email::Find -> new ( sub { return sprintf ($email_link,$_[0]->format,$_[1]); } ); $call=sub { my $text=shift; $finder -> find (\$text); return $text; }; } $finder -> find ($text, $call); } } #--------# |