php extract email from string
<?php
function fetch_mails($text){
//String that recognizes an e-mail
$str = '/([a-z0-9_\.\-])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+/i';
preg_match_all($str, $text, $out);
//return a blank array if not true otherwise insert the email in $out and return
return isset($out[0]) ? $out[0] : array();
}
//string to be checked
$tstr = '
My first e-mail address is [email protected]
My second e-mail address is [email protected]
Obviously this is not a emaail address: code__speedy@^gmail.co.in
';
//display email addresses
echo"<pre>";
print_r(fetch_mails($tstr));
?>