Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace http:// with < a href = http: . . . . . 1

Status
Not open for further replies.

ednit

Technical User
Jan 31, 2006
16
US
I have text (articles) with links that I want to transform to html. I am having a hard time figuring out how to change a link like this:


To this:

<a href="
I am looking for something like:

$article =~ s/http:. . /<a href=http. . . </a>/g;

But I have no idea how to create it.

Any help is appreciated. Thanks.
 
since there can't be sapces in urls. your probably best to use the first space after the url as the end point of the match:

Code:
my $string = 'Some text with a url [URL unfurl="true"]http://example.com[/URL] in it';
$string =~ s|(http://[^ ]+)|<a href="$1">$1</a>|ig;
print $string;
 
Thank you very much!

That is what I was looking for & it works just as it should.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top