note 32399 deleted from function.preg-replace by sniper

From: Date: Sun, 07 Sep 2003 21:56:35 +0000
Subject: note 32399 deleted from function.preg-replace by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-55669@lists.php.net to get a copy of this message
Note Submitter: ed1@anastas.org ---- IMPROVED LINK CREATOR I created a function which converts links also, with the help of everyone who has posted above, but one thing seemed to be left out... Nobody seemed to address the issue of shorthand domain names like php.net or even www.php.net so I created a function that tries to incorporate all the comments above and allows shorthand domain links as well. If anyone can improve on this I would appreciate it. NOTES:regarding shorthand domains, I only match the most common domain extension like .com or .net (see code below for more) because I was having problems with P.O.BOX address submissions. This may be improved on. CODE ----------------------------------------------------------- function html_links($text) { $tld = "com|net|org|ws|name|info|biz|tv"; return preg_replace( array ( // (_|^)domain.???(_|$|.$) // DOMAIN "/(\s{1}|\A)(\w+\.)($tld)(\.)?(\s{1}|\Z)/i", // (_|^)ftp.domain.???(_|$|.$) // SUBDOMAIN.DOMAIN "/(\s{1}|\A)(ftp.)(\w+\.)($tld)(\.)?(\s{1}|\Z)/i", // (_|^)???.domain.???(_|$|.$) // FTP.DOMAIN "/(\s{1}|\A)(\w+\.)(\w+\.)($tld)(\.)?(\s{1}|\Z)/i", // (HTTP/FTP)://DOMAIN "/(ht|f)(tp)(s|7)?(:\/\/)?([\w+\.]+) ([\w\.\/\=\?\-\~\!\@\#\$\&]*)/i", // EMAIL ADDRESS "/(\s{1}|\A)((\w)+\:)?([\w\.\_\-]+) (@)([\w\.]+)(\s{1}|\Z)/i"), array ( // DOMAIN " http://www.$2$3 ", // SUBDOMAIN.DOMAIN " ftp://$2$3$4 ", // FTP.DOMAIN " http://$2$3$4 ", // (HTTP/FTP)://DOMAIN " <A TARGET=$target HREF=\"$1$2$3$4$5$6\">$5</A> ", // EMAIL ADDRESS " <A HREF=\"mailto:$4$5$6\">$4$5$6</A> "), $text); }

« previous php.notes (#55669) next »