I have a string which contains anywhere from 0 to multiple webpage addresses, which I want to convert to HTML clickable links when I print the string.
Example: $before = 'http://www.mysite.com http://theotherone.co.uk http://www.maybeantother';
$after = '<a href = "http://www.mysite.com">http://www.mysite.com </a> etc';
Regardless of spaces between URL, or the number of URLS (inlcuding 0).
I guess this is just a "convert anything that looks like a URL to a URL'.
I have looked in the GT Docs and found things like deparse_url, which does not seem to be what I want.
I have also found various functions by searching the net, but none seem to exactly match this.
Example junk:
sub hyperlink
{
$_ = shift;
s/&/&/g;
s/</</g;
my $new;
while (m/=\?iso-8859-1\?Q\?([^\?]*)\?=/)
{
$new = $1;
$new =~ s/=(\w\w)/"&#".hex($1).";"/gie; # Convert quoted-printable
s/=\?iso-8859-1\?Q\?[^\?]*\?=/$new/;
}
s&(ftp|gopher|http)(://[^<>),"\&\s]*[^<>),."\&\s])&<A HREF="$1$2">$1$2</A>&g;
s&(mailto|news|telnet)(:[^<>)\],"\s]+)&<A HREF="$1$2">$1$2</A>&g;
s&(^|\s)(ftp|gopher)(\.[\w./-]+)(\s|$)&$1<A HREF="$2://$2$3/">$2$3</A>$4&g;
s&(^|\s)(www\.[\w./-]+)(\s|$)&$1<A HREF="http://$2/">$2</A>$3&g;
s&(article|In-Reply-To:|Message-ID:|References:)(\s+\<)([^@>"\s]+@[^>"\s]*)&$1$2<A HREF="$3">$3</A>&gi;
s/(^|^"|[^=]"|SMTP:|[()\[\]\s]|(<)+)([^&()>":\[\]\s]+@)([\w\-.]+\.[\w\-]+|\[\d+\.\d+\.\d+\.\d+\])/$1<A HREF="mailto:$3$4">$3$4<\/A>/g;
return $_;
}
Is there a perl module that this is already built into? or better still a simple regex or function I could use?
http://www.iuni.com/...tware/web/index.html
Links Plugins
Example: $before = 'http://www.mysite.com http://theotherone.co.uk http://www.maybeantother';
$after = '<a href = "http://www.mysite.com">http://www.mysite.com </a> etc';
Regardless of spaces between URL, or the number of URLS (inlcuding 0).
I guess this is just a "convert anything that looks like a URL to a URL'.
I have looked in the GT Docs and found things like deparse_url, which does not seem to be what I want.
I have also found various functions by searching the net, but none seem to exactly match this.
Example junk:
Code:
# hyperlink: Generate HTML link sub hyperlink
{
$_ = shift;
s/&/&/g;
s/</</g;
my $new;
while (m/=\?iso-8859-1\?Q\?([^\?]*)\?=/)
{
$new = $1;
$new =~ s/=(\w\w)/"&#".hex($1).";"/gie; # Convert quoted-printable
s/=\?iso-8859-1\?Q\?[^\?]*\?=/$new/;
}
s&(ftp|gopher|http)(://[^<>),"\&\s]*[^<>),."\&\s])&<A HREF="$1$2">$1$2</A>&g;
s&(mailto|news|telnet)(:[^<>)\],"\s]+)&<A HREF="$1$2">$1$2</A>&g;
s&(^|\s)(ftp|gopher)(\.[\w./-]+)(\s|$)&$1<A HREF="$2://$2$3/">$2$3</A>$4&g;
s&(^|\s)(www\.[\w./-]+)(\s|$)&$1<A HREF="http://$2/">$2</A>$3&g;
s&(article|In-Reply-To:|Message-ID:|References:)(\s+\<)([^@>"\s]+@[^>"\s]*)&$1$2<A HREF="$3">$3</A>&gi;
s/(^|^"|[^=]"|SMTP:|[()\[\]\s]|(<)+)([^&()>":\[\]\s]+@)([\w\-.]+\.[\w\-]+|\[\d+\.\d+\.\d+\.\d+\])/$1<A HREF="mailto:$3$4">$3$4<\/A>/g;
return $_;
}
Is there a perl module that this is already built into? or better still a simple regex or function I could use?
http://www.iuni.com/...tware/web/index.html
Links Plugins