note 20739 deleted from function.ereg-replace by sander
| From: | sander@php.net | Date: | Tue, 16 Apr 2002 14:13:42 +0000 |
| Subject: | note 20739 deleted from function.ereg-replace by sander | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-29430@lists.php.net to get a copy of this message | ||
If you want to replace URL with Links, you can't just replace www.php.net, because someone can
write http://www.php.net
use this:
$string = preg_replace
("(http://[a-zA-Z1-9\-_\.]+\.[a-zA-Z1-9\-_]+\.[a-z]{2,3})","<a
href=\"\\0\" target=\"_blank\">\\0</a>", $string);
$string = preg_replace
("([ |\n][a-zA-Z1-9\-_\.]+\.[a-zA-Z1-9\-_]+\.[a-z]{2,3})", "<a href=\"http://\\0\" target=\"_blank\">\\0</a>",
$string);
the second one will only replace strings without something (a return or a space) in front.
also, for e-mails:
$string = preg_replace("([a-z]{1}[a-z1-9_\-\.]*@[a-z1-9]+\.[a-z]{2,3})",
"<a href=\"mailto:\\0\">\\0</a>",$string);