Re: [PHP] wrapping anchor tags around a URL
On 1/26/06, Richard K Miller [EMAIL PROTECTED] wrote: @(http://\S+)(?!\.)@ -- this still captures everything @(http://\S+?)(?!\.)@-- this captures too little hmm maybe this would work? @http://.+(?=\.)@
Re: [PHP] wrapping anchor tags around a URL
On 1/23/06, Richard K Miller [EMAIL PROTECTED] wrote: function link_the_links($s) { return preg_replace('@(http://[^\s]+)@sm', 'a href=$1$1/a', $s); } I've got to somehow ignore the trailing period if it is present. if ($s[strlen($s)-1] == '.'){ $s = substr($s, 0, -1); } -ahmed
Re: [PHP] wrapping anchor tags around a URL
On 1/25/06, Ahmed Saad [EMAIL PROTECTED] wrote: On 1/23/06, Richard K Miller [EMAIL PROTECTED] wrote: function link_the_links($s) { return preg_replace('@(http://[^\s]+)@sm', 'a href=$1$1/a', $s); } if ($s[strlen($s)-1] == '.'){ $s = substr($s, 0, -1); } oops! sorry i thought $s had only one link (per time) no all of them -ahmed
Re: [PHP] wrapping anchor tags around a URL
On 1/25/06, Ahmed Saad [EMAIL PROTECTED] wrote: On 1/25/06, Ahmed Saad [EMAIL PROTECTED] wrote: On 1/23/06, Richard K Miller [EMAIL PROTECTED] 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 -ahmed
Re: [PHP] wrapping anchor tags around a URL
On Jan 25, 2006, at 10:01 AM, Ahmed Saad wrote: On 1/25/06, Ahmed Saad [EMAIL PROTECTED] wrote: On 1/25/06, Ahmed Saad [EMAIL PROTECTED] wrote: On 1/23/06, Richard K Miller [EMAIL PROTECTED] 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] wrapping anchor tags around a URL
I wrote a little function to put anchor tags around a URL. We're using it to make URL's in paragraphs of text linkable: function link_the_links($s) { return preg_replace('@(http://[^\s]+)@sm', 'a href=$1$1/a', $s); } Its only flaw (besides a goofy name) is that if a link comes at the end of a sentence, right before the period, the period ends up in the link, thus breaking the link. I've got to somehow ignore the trailing period if it is present. Any ideas? Richard K Miller -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php