tags:

views:

185

answers:

1

Say i have a string of text such as

$text = "Hello world, be sure to visit http://whatever.com today";

how can i (probably using regex) insert the anchor tags for the link (showing the link itself as the link text) ?

+2  A: 

You can use regexp to do this:

$html_links = preg_replace('"\b(http://\S+)"', '<a href="$1">$1</a>', $text);
Ivan Nevostruev