title: Replace links in content with hyperlinks using Regular Expressions
body: <p>I have a string which contains a user's blog content.  If they include the following:</p>
  
  <pre><code>www.google.com
  http://google.com
  http://www.google.com
  </code></pre>
  
  <p>in their blog post, I want PHP to replace these occurrences with a real hyperlink, but maintain the original substring (i.e. not change <code>www.google.com</code> to <code>http://www.google.com</code>).</p>
  
  <p>Does anybody know how I might do this with PHP and regular expressions?  I've tried this:</p>
  
  <pre><code>echo preg_replace('/((www|http:\/\/)[^ ]+)/', '&lt;a href="$1" target="_blank"&gt;$1&lt;/a&gt;', $content);
  </code></pre>
  
  <p>But this only succeeds if you end the link with a space. Fails if you end it with a comma or full stop.</p>