Home › Forums › Back End › Php/Javascript to Find All Email Addresses, and Make Links From Them. › Re: Php/Javascript to Find All Email Addresses, and Make Links From Them.
December 12, 2011 at 3:17 pm
#92558
Member
Something along the lines of this? :
$content ='[email protected] [email protected]
';
$addr_pattern = '/([A-Z0-9._%+-]+)@([A-Z0-9.-]+).([A-Z]{2,4})(((.+?)))?/i';
preg_match_all($addr_pattern, $content, $addresses);
$the_addrs = $addresses[0];
for ($a = 0; $a < count($the_addrs); $a++) {
$repaddr[$a] = preg_replace($addr_pattern, '$1@$2.$3', $the_addrs[$a]);
}
$cc = str_replace($the_addrs, $repaddr, $content);
echo $cc;
?>
based on : http://stackoverflow.com/questions/5068676/regex-to-detect-plain-email-and-mailto-link-emails