PDA

View Full Version : Parsing for emails


09-05-2000, 06:15 PM
Can anyone whip up a quick hack which parses the contents of a message for an email address (probably looking for the @ sign) and automatically adds the email tags to it, similarly to automatically parsing for URL's.

09-06-2000, 01:21 PM
I believe that$messagetext = eregi_replace("([_a-z0-9-]+(\.[_a-z0-9-]+)*)@([a-z0-9-]+(\.[a-z0-9-]+)*)","<A HREF=\"mailto:\\1@\\3\">\\1@\\3</A>",$messagetext);will work. This one does not do any validation; it just looks for something@something. You might also try throwing some weird addresses at it to see if the \\1@\\3 part remains valid for all forms of "." separated names.

09-06-2000, 11:17 PM
That seems to have worked great. It only works if HTML is on in a forum, otherwise it prints the tags.
Thanks!

09-07-2000, 04:07 PM
You can better do it this way to keep up the consistency with Vb, in this case it doesn't matter if html is turned on or off:

$messagetext = eregi_replace("([_a-z0-9-]+(\.[_a-z0-9-]+)*)@([a-z0-9-]+(\.[a-z0-9-]+)*)","\\1@\\3",$messagetext);

untested but I think it'll work

NB: Replace _email with email (twice)

[Edited by Mas*Mind on 09-07-2000 at 01:09 PM]