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

Answer: How do I replace a URL with a clickable hyperlink?

by tachyon (Chancellor)
on Feb 14, 2002 at 14:45 UTC ( #145453=categorized answer: print w/replies, xml ) Need Help??

Q&A > regular expressions > How do I replace a URL with a clickable hyperlink? - Answer contributed by tachyon

$text = <<TEXT; Hello World http://www.world.com/index.htm http://foo.com http://bar.com TEXT ($links = $text) =~ s!(http://[^\s]+)!<a href="$1">$1</a>!gi; print $text,"\n\n",$links;

Replies are listed 'Best First'.
Re: Answer: How do I replace a URL with a clickable hyperlink?
by merlyn (Sage) on Feb 14, 2002 at 16:12 UTC
    This is wrong, of course, for unusual links that contain HTML-nasty characters, unless you presume that the input contains no quotes and is already HTML-safe.

    -- Randal L. Schwartz, Perl hacker

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2017-06-28 07:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (628 votes). Check out past polls.