in reply to Adding href where needed.
If the user input is www.perlmonks.com or http://www.perlmonks.com it will give you the proper URI. In this case with html code:#!/usr/bin/perl use strict; use URI::Heuristic qw(uf_uristr); my $url = uf_uristr("www.perlmonks.com"); print "<a href=$url>$url</a>\n";
This works just fine, also with resolving the url to an uri. You may also drag out the text by enclosing the last .* and drag out the value of $2.#!/usr/bin/perl use URI::Heuristic qw(uf_uristr); use strict; my $url; my $input = "<a href = http://www.perlmonks.com>perlmonks</a>"; #my $input = "www.perlmonks.com"; if ($input =~ /^</) { $input =~ /<a\s+href\s*=\s*(.*)>.*<\/a>/i; $url = uf_uristr("$1"); } else { $url = uf_uristr("$input"); } print "<a href=$url>$url</a>";
|
|---|