note 39853 deleted from function.ereg-replace by tularis
| From: | tularis@php.net | Date: | Sun, 29 Aug 2004 12:12:56 +0000 |
| Subject: | note 39853 deleted from function.ereg-replace by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-75553@lists.php.net to get a copy of this message | ||
Note Submitter: Krzysiek Kobrzak kobrzak at wp dot pl
----
Another proposal for those who are looking for some nice "replace URLs with links" script.
Actually I found bugs in all the suggestions above. My script replaces URLs and e-mail addresses no
matter how many of them there are in the string. The URL must start with "http: // (ftp, https)", "http: // www" or just
"www".
function url_to_link($str)
{
global $str;
$str = eregi_replace ("[[:alpha:]]+://www", "www",$str);
$str = ereg_replace
("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/](\.[a-z0-9-]{2,4})+", "<a
href=\\0 target=_blank>\\0</a>", $str);
$str = ereg_replace ("www.[^<>[:space:]]+[[:alnum:]/](\.[a-z0-9-]{2,4})+",
"<a href=http://\\0 target=_blank>\\0</a>", $str);
$str = ereg_replace ("[[:alpha:]]+@[^<>[:space:]]+[[:alnum:]/](\.[a-z0-9-]{2,4})+",
"<a href=mailto:\\0 target=_blank>\\0</a>", $str);
}