<?xml version="1.0" encoding="UTF-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
  <title>Latest snippets tagged regexp</title>
  <link rel="alternate" href="http://snippets.prendreuncafe.com/snippets/tagged/regexp/order_by/date"></link>
  <id>http://snippets.prendreuncafe.com/snippets/tagged/regexp/order_by/date</id>
  <updated>2009-11-18T14:18:45Z</updated>
  <author>
    <name>Symfony</name>
    <author_email>noreply@symfony-project.com</author_email>
  </author>
<entry>
  <title>replace url by links in a text</title>
  <link href="http://snippets.prendreuncafe.com/snippet/102"></link>
  <updated>2009-11-18T14:18:45Z</updated>
  <id>102</id>
  <summary type="html">[code]
  static function urlMe($text){
    $pattern = &quot;@(http://|https://){1}((www\.?)[a-zA-Z0-9\-\.]+\.[a-z]{2,6})/?([^\s]*)@&quot;;
    preg_match_all($pattern,' '.$text.' ',$matches);
    foreach($matches[2] as $offset =&gt; $link){
      $text = str_replace($matches[0][$offset],'&lt;a href=&quot;'.$matches[0][$offset].'&quot; title=&quot;'.$matches[0][$offset].'&quot;&gt;'.$link.'&lt;/a&gt;',$text);
    }
    return($text);
  }
[/code]</summary>
</entry>
</feed>
