title: Replacing Text link as link with preg_replace
body: <p>I seem to be having an issue replacing a text link with a link to the site posted, it isn't linking.</p>
  
  <p>The code:</p>
  
  <pre><code>$status_text = preg_replace('#(\A|[^=\]\'"a-zA-Z0-9])(http[s]?://(.+?)/[^()&lt;&gt;\s]+)#i', '\\1&lt;a href="\\2"&gt;\\3&lt;/a&gt;', $status_text);
  echo $status_text;
  </code></pre>
  
  <p><code>$status_text</code> is pulled from a MySQL field named <code>contents</code>, and contains other text, but i'd just like to linkify the link. <em>Additionally</em>, i'd also like it to not display the full URL, just the main domain.</p>
  
  <p>UPDATE: We have two other preg_replaces on the same page, looking for things with + and # in front of them that link to areas of the site, they currently work and need to not conflict with the above:</p>
  
  <pre><code>$status_text = preg_replace("/#([a-z_0-9]+)/i", "&lt;a href=\"http://url.com/hashlink/$1\"&gt;$0&lt;/a&gt;", $status_text);
  
  
  $status_text = preg_replace("/\+([a-z_0-9]+)/i", "&lt;a href=\"http://url.com/pluslink/$1\"&gt;$0&lt;/a&gt;", $status_text);
  </code></pre>