note 15751 deleted from function.ereg-replace by jimw

From: Date: Fri, 02 Nov 2001 02:00:03 +0000
Subject: note 15751 deleted from function.ereg-replace by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-20221@lists.php.net to get a copy of this message
After reading up and finding a million different Text-to-URL expressions and functions I grabbed this one from the list and modified it slightly to actually work in pretty much all instances. Credit goes to those who actually first developed the expressions. function TextToUrls($str) { $str = ereg_replace("((www.)([a-zA-Z0-9@:%_.~#-\?&]+[a-zA-Z0-9@:%_~#\?&/]))", "http://\\1", $str); $str = ereg_replace("(ftp://|http://|https://)(ftp://|http://|https://)([a-zA-Z0-9@:%_.~#-\?&]+[a-zA-Z0-9@:%_~#\?&/])", "\\1\\3", $str); $str = ereg_replace("(((ftp://|http://|https://){1})[a-zA-Z0-9@:%_.~#-\?&]+[a-zA-Z0-9@:%_~#\?&/])", "<a href=\"\\1\" target=\"_blank\">\\1</a>", $str); $str = ereg_replace('[A-Za-z0-9]([A-Za-z0-9._]*[A-Za-z0-9]|())@[A-Za-z0-9]([A-Za-z0-9.\-]*[A-Za-z0-9]|())\.[A-Za-z]+', '<a href="mailto:\\0">\\0</a>', $str); return $str; }

« previous php.notes (#20221) next »