Re: Converting URL's to hyperlinks.
| From: | Lupus Michaelis | Date: | Fri, 04 Sep 2009 14:46:13 +0000 |
| Subject: | Re: Converting URL's to hyperlinks. | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-297679@lists.php.net to get a copy of this message | ||
Daevid Vincent a écrit :
Maybe I misunderstood the OP, OP ?
but wouldn't this (or something like it) be easier and cleaner than that mess below?? No, it's dirty too.
$url = preg_replace("/(\w+@\w+\.[a-zA-Z]{2,3})/i", "<a href='mailto:$1'>$1</a>", $url); This violate the numerous RFC about mail addresses, and some other stuffs.
$url = preg_replace("/\s(http:\/\/)?(\w*\.?\w*\.[a-zA-Z]{2,3}.*?\s)/i", " <a href='http://$2' target='_blank'>$2</a>", $url);Same as previously. What about .info, .museum and so on tld ? The filter_var is well suited for this kind of job. Oh, and your regex isn't smart (you use the case insensitivity flag, but seek A-Z characters...) :D -- Mickaël Wolff aka Lupus Michaelis http://lupusmic.org