Automatic Linkification for network files in PHP
I'm trying to automatically detect links in user-submitted text and dynamically generate links. I've found that this works well for "normal" URLs.
$pattern = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
return preg_replace($pattern, "<a href=\"\\0\" rel=\"nofollow\" target=\"_blank\">\\0</a>", $str);
Is there a way this could be expanded to cover UNC or map开发者_开发知识库ped network drives such as \\ComputerName\SharedFolder\File.txt
or Z:\Dir\File.txt
?
I'm not necessarily looking for a perfect solution.
The most obvious non perfect solution is to just have three patterns and check each one in turn. (So, look for \\ and [A-Z]:\ and grab everything up to the first whitespace.)
精彩评论