I have a string that contains text and several email addresses. I am trying to turn the emails addresses into clickable links.
I have read everything here:
http://www.regular-expressions.info/email.html
and here:
http://www.markussipila.info/pub/emailvalidator.php
and I've read the PHP manual in the appropriate sections but I still can't seem to match (hence replace) anything and I don't know what I am doing wrong.
My code is:
// I tried all of the following:
//$pattern = '/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])'.'(([a-z0-9-])*([a-z0-9]))+'.'(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i';
//$pattern = "^[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})$";
//$pattern = "^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$";
$pattern = '\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b';
echo preg_replace($pattern,'<a href="mailto:\\0">\\0</a>',$schedule);
Where am I stubmbling?