1

Possible Duplicate:
How to parse/trim email addresses from text

How can I extract email address from a list of names and email addresses?

Example input:

"a1 b.d"<a1@test.com>,
<a2@test.com>,
"a3 b.d"<a3@test.com> ,
a4@test.com ,

Output :

a1@test.com,
a2@test.com,
a3@test.com,
a4@test.com,
Community
  • 1
  • 1
Thulasiram
  • 8,432
  • 8
  • 46
  • 54

2 Answers2

0
function extract_emails_from($string) {
         preg_match_all("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $string, $matches);
         return $matches[0];
}

Thinks Following this URL will help you.

http://css-tricks.com/snippets/php/extract-email-addresses/

Avin Varghese
  • 4,340
  • 1
  • 22
  • 31
0

This PHP function will extract an email address from a string and put it into a clickable link:

function extractEmail( $data )
{
    if ( preg_match( "/[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}/i", $data, $email ) )
    {
        $replacement = '<a href="mailto:' . $email[ 0 ] . '" target="_blank">' . $email[ 0 ] . '</a> ';
        $data        = preg_replace( "/[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}/i", $replacement, $data );
    }
    return $data;
}

To use it create PHP file and add there a test entry (but not forget to place the function above in it):

<?php
  echo extractEmail("Some text goes here before mail@mail.com and some text here goes after");
?>
Ilia Ross
  • 13,086
  • 11
  • 53
  • 88