Re: function that makes http into <ahref
| From: | Daniel Convissor | Date: | Tue, 08 Aug 2000 15:01:06 +0000 |
| Subject: | Re: function that makes http into <ahref | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-10735@lists.php.net to get a copy of this message | ||
Hi Y'all:
> Anyone got a function that parses a text string and turns everything that
> looks like a url into a clickable url?
Here's something I whipped up:
// Help // * URI's are automatically converted to hyperlinks. This
// Help // covers anything starting with a known transport scheme:
// Help // (http://, https://, ftp://, gopher://, news:, mailto:)
// Help // Note, this process properly recognizes URI's which use
// Help // characters authorized by RFC 2396. The hyperlink will stop
// Help // at the point where the first illegal character appears.
// Help // Also, while "." and "," are valid characters, when they
// Help // appear at the end of a URI, we consider them punctuation
// Help // rather than part of the URI. If you have a URI ending with
// Help // such, escape them using "%46" or "%44".
$Val =
eregi_replace("(http://|https://|ftp://|gopher://|news:|mailto:)([[:alnum:]/!#$%&'()*+,.:;=?@~-]+)([[:alnum:]/!#$%&'()*+:;=?@~-])",
"<a href=\"\\1\\2\\3\">\\1\\2\\3</a>", "$Val");
Where the $Val going in is the entire string you wish to check and the $Val
going out is the same text with all links turned into hyperlinks.
Enjoy,
--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
More than just answers. Solutions. (SM)
http://www.analysisandsolutions.com/
4015 7 Av #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409