Welcome to WebmasterWorld Guest from 54.204.162.36

Forum Moderators: coopster & jatar k & phranque

Replacing URLs with Links

   
10:54 am on Aug 7, 2008 (gmt 0)

5+ Year Member



Does anyone have a regex for giving a string for a link to a URL.
I need to write a link within my website to another website.

i think i need to use the s/// replacement operator.

5:43 pm on Aug 7, 2008 (gmt 0)

5+ Year Member



give an example of the input data and desired output data, your question is not very clear.
1:23 am on Aug 8, 2008 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Well not regex, but . . . run it on a command line, extract whatcha need.


#!/usr/bin/perl
until ($input =~ /^q/i) {
print "Type a full URL to test, q to quit:\n";
chomp($input = <STDIN>);
if ($input =~ /^q/i) { last; }
unless ($input =~ /^http/i) { $input = 'http://' . $input; }
$title = $input;
$title =~ s/https*:\/\/(www\.)*//i;
$link = qq<a href="$input">$title</a>;
print "Link code is $link\n";
}
print "exiting program\n";

[edited by: phranque at 5:29 am (utc) on Aug. 8, 2008]
[edit reason] disabled smileys ;) [/edit]

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month