Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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("www.perlmonks.com"); print "<a href=$url>$url</a>\n";
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:
<a href=http://www.perlmonks.com>http://www.perlmonks.com</a>
using www.perlmonks.com as input.
It also does ftp and others.

ok..it's a bit off what you really asked for but i just noted this module at CPAN and liked it ;o)

Update:
#!/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>";
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.

In reply to Re: Adding href where needed. by moen
in thread Adding href where needed. by electronicMacks

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2024-04-18 17:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found