Re: wrapping anchor tags around a URL

From: Date: Thu, 26 Jan 2006 05:00:20 +0000
Subject: Re: wrapping anchor tags around a URL
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-229292@lists.php.net to get a copy of this message
On Jan 25, 2006, at 10:01 AM, Ahmed Saad wrote:
On 1/25/06, Ahmed Saad <ahmed.lists@gmail.com> wrote:
On 1/25/06, Ahmed Saad <ahmed.lists@gmail.com> wrote:
On 1/23/06, Richard K Miller <richardkmiller@gmail.com> wrote:
function link_the_links($s) {
        return preg_replace('@(http://[^\s]+)@sm', '<a href="$1">$1</a>', $s);
}
try "looking ahead" in the first regex http://www.regular-expressions.info/lookaround.html
Wow, I was really glad you found that. I had never heard of this before, but it looks like the solution. However, my real life example still isn't working, even after adding what I think was the right look-ahead expression: @(http://\S+)(?!\.)@ -- this still captures everything
@(http://\S+?)(?!\.)@    -- this captures too little
Any ideas? In any case, thanks for the article -- that was informative. Richard

« previous php.general (#229292) next »