phone

How to extract email address from a string using preg_match in php

email-extractEver wanted to extract or scrap an email from a string or some content without using simple html dom or a parser such as LIB_parse.php. If you are creative enough you can incorporated this into a function that goes from one URL to the next extracting email address through the same or related domains. Here is a quick example:

// check to see if there is a match
preg_match(“/[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}/”,$phone, $matches);

// for each match print email
foreach ($matches as $matches) {
echo $matches.’
‘;
}

Grow Your Business. Call: 256-361-9080

Leave a Reply