Find Email From PHP String

On May 3, 2012, in LAMP, PHP, Web Application, by Sandeep Verma

Hits: 4015  

<?php
function lower($n)

{

return( strtolower(str_replace(” ““”$n)) );

}

$string "Hello Friends, I am Sandeep Verma. My Emails are infos@svnlabs.com, sandeepv @svnlabs.com, svnlab @ gmail.com and svmbm@ svnlabs.com. Do you know we can use this code to get emails from a PHP String. Also code is converting emails to proper case like Sandeepv @svnlabs.com and sandeepv@svnlabs.com are same. But contact me here infos@scriptrr.com";

preg_match_all("/[_a-z0-9-]+(\.[_a-z0-9-]+)*([ ]{0,2})@[a-z0-9- ]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})/i"$string$matches);

$lower array_map("lower"$matches[0]);

$result array_unique($lower);

print_r($result);

?>

Output:

Array ( [0] => infos@svnlabs.com [1] => sandeepv@svnlabs.com [2] => svnlab@gmail.com [3] => svmbm@svnlabs.com [6] => infos@scriptrr.com )







Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...