Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Adding href where needed.

by moen (Hermit)
on Oct 31, 2000 at 05:29 UTC ( #39226=note: print w/replies, xml ) Need Help??

in reply to Adding href where needed.

You should maybe look into URI::Heuristic for completing your links. Something like this:
#!/usr/bin/perl use strict; use URI::Heuristic qw(uf_uristr); my $url = uf_uristr(""); print "<a href=$url>$url</a>\n";
If the user input is or it will give you the proper URI. In this case with html code:
<a href=></a>
using as input.
It also does ftp and others.'s a bit off what you really asked for but i just noted this module at CPAN and liked it ;o)

#!/usr/bin/perl use URI::Heuristic qw(uf_uristr); use strict; my $url; my $input = "<a href =>perlmonks</a>"; #my $input = ""; 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>";
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.
The regex should work on it's own without using the module also, me thinks.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://39226]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2022-05-20 13:44 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (73 votes). Check out past polls.