2

Possible Duplicate:
What is the PHP regex to convert text containing a URL into a hyperlink?

How can I turn a string like this:

My Name, http://www.mysite.com

into

<a href="http://www.mysite.com">My Name</a>

using regex?

Basically I want to autodetect if a URL is present in the string, and turn it into a link if it is. And if a name is not present then turn the link into something like

<a href="http://www.mysite.com">mysite.com</a>
Community
  • 1
  • 1
Emma
  • 21
  • 1
  • Why close it? This is not exact duplicate! Here is how you can do it `$str = 'My Name, http://mysite.com'; $link = preg_replace('/([^,]+),\s(.+)/', '$1', $str);`. – Shef Aug 08 '11 at 15:47
  • Related/Duplicate: [`make_clickable()`](http://stackoverflow.com/questions/6861324/how-to-extract-http-links-from-a-paragraph-and-store-them-in-a-array-on-php/6861706#6861706) – hakre Aug 08 '11 at 16:05

0 Answers0