note 27673 deleted from function.preg-replace by sniper
| From: | sniper@php.net | Date: | Sun, 07 Sep 2003 22:04:09 +0000 |
| Subject: | note 27673 deleted from function.preg-replace by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-55693@lists.php.net to get a copy of this message | ||
Note Submitter: mdreed@mac.com
----
Someone pointed out to me that there is a slight problem with my HTMLEncode function. It
won't, for example, encode "http://www.example.com/~root/" correctly
(it'll only make "http://www.example.com/" a link and leave
"~root/" as text). Here's the fixed version:
function HTMLEncode($text) {
return nl2br(preg_replace(array("/(([\w\.]+))(@)([\w\.]+)\b\~/i",
"/((ftp(7?):\/\/)|(ftp\.))([\w\.\/\&\=\?\-\~]+)/",
"/((http(s?):\/\/)|(www\.))([\w\.\/\&\=\?\-\~]+)/"), array("<a href=\"mailto:$0\" style=\"color:blue;
text-decoration:none\">$0</a>", "<a href=\"ftp$3://$4$5\"
target=\"_blank\" style=\"color:blue;
text-decoration:none\">$4$5</a>", "<a href=\"http$3://$4$5\"
target=\"_blank\" style=\"color:blue;
text-decoration:none\">$4$5</a>"), $text));
}
If anyone finds any more problems with this function, please tell me so I can fix them. I would
imagine that there are plenty of websites that use this type of function, so any problems with it
have the potential for widespread slight inconvenience!