note 20739 added to function.ereg-replace
| From: | andreas dot schempp at gmx dot ch | Date: | Sun, 14 Apr 2002 21:27:08 +0000 |
| Subject: | note 20739 added to function.ereg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-29301@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);
--
http://www.php.net/manual/en/function.ereg-replace.php
http://master.php.net/manage/user-notes.php?action=edit+20739
http://master.php.net/manage/user-notes.php?action=delete+20739
http://master.php.net/manage/user-notes.php?action=reject+20739