note 15751 added to function.ereg-replace

From: Date: Mon, 01 Oct 2001 19:04:24 +0000
Subject: note 15751 added to function.ereg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-18439@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; } -- http://www.php.net/manual/en/function.ereg-replace.php http://master.php.net/manage/user-notes.php?action=edit+15751 http://master.php.net/manage/user-notes.php?action=delete+15751 http://master.php.net/manage/user-notes.php?action=reject+15751

« previous php.notes (#18439) next »