I have a block of text from which I want to extract the valid e-mail addresses and put them into an array. So far I have...
$string = file_get_contents(\
This function works fine without using regex. So it is really faster and low resource hungry.
", ";", "'", ". ");
$str = str_replace( $remove_chars, ' ', $str );
$parts = explode(' ', $str);
if(count($parts) > 0){
foreach($parts as $part){
$part = trim($part);
if( $part != '' ) {
if( filter_var($part, FILTER_VALIDATE_EMAIL) !== false){
$emails[] = $part;
}
}
}
}
if(count($emails) > 0){
return $emails;
}
else{
return null;
}
}
$string = "Guys, please help me to extract valid sam-ple.1990@gmail.co.uk email addresses from some text content using php
example , i have below text content in mysql database ' Life is more beautiful, and i like to explore lot please email me to sample@gmail.com. Learn new things every day. 'from the above text content i want to extract email address 'sample-x@gmail.com' using php regular expressions or other method.";
$matches = extract_email_addresses( $string );
print_r($matches);
?>