title: PHP Regular Expression Text URL to HTML Link
body: <p>I'm working on a project where I need to replace text urls anywhere from <code>domain.com</code> to <code>www.domain.com</code> to <code>http(s)://www.domain.com</code> and e-mail addresses to the proper html <code>&lt;a&gt;</code> tag. I was using a great solution in the past, but it used the now depreciated <code>eregi_replace</code> function. On top of that, the regular expression used for such function does not work with <code>preg_replace</code>.</p>
  
  <p>So basically, the user inputs a message in which may/may not contain a link/e-mail address and I need a regular expression that works with <code>preg_replace</code> to replace that link/email with a HTML link like <code>&lt;a href="link"&gt;link&lt;/a&gt;</code>.</p>
  
  <p>Please note that I have multiple other preg_replaces too. Below is my current code for the <strong>other</strong> replacements being made.</p>
  
  <pre><code>$patterns = array('~\[@([^\]]*)\]~','~\[([^\]]*)\]~','~{([^}]*)}~','~_([^_]*)_~','/\s{2}/');
  $replacements = array('&lt;b class="reply"&gt;@\\1&lt;/b&gt;','&lt;b&gt;\\1&lt;/b&gt;','&lt;i&gt;\\1&lt;/i&gt;','&lt;u&gt;\\1&lt;/u&gt;','&lt;br /&gt;');
  $msg = preg_replace($patterns, $replacements, $msg);
  return stripslashes(utf8_encode($msg));
  </code></pre>