Here is simple code to grab email address from any PHP string. Code is using preg_match_all with regular expression below…
But I want to suggest you to use some code to hide emails from your websites else spammer will attack your inbox.
<?php
function lower($n)
{
return( strtolower(str_replace(” “, “”, $n)) );
}
$string = "Hello Friends, I am Sandeep Verma. My Emails are [email protected], 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 [email protected] are same. But contact me here [email protected]";
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] => [email protected] [1] => [email protected] [2] => [email protected] [3] => [email protected] [6] => [email protected] )