Forum Moderators: coopster & phranque

Message Too Old, No Replies

Replacing URLs with Links

         

Davo1977

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

10+ 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.

perl_diver

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

10+ Year Member



give an example of the input data and desired output data, your question is not very clear.

rocknbil

1:23 am on Aug 8, 2008 (gmt 0)

WebmasterWorld Senior Member 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]