Extract Email addresses from a webpage – PHP Script!

Lets say you have a very long webpage with a lot of text content and email addresses in it, If you want to take out only the email addresses manually, it is not very easy. It will take plenty of your time to extract all of them and there is a chance we miss some of the email addresses!

To avoid such kind of trouble and to save your time, I have written a PHP script which will help you to get what you want!

In this script I’m using regular expression to extract the email addresses, here is the pattern:

The above regex pattern will extract all kind of email addresses even with IP address like (superscript@
So, here is the entire HTML and PHP part, just copy this file and save it as (anyname.php):

The above script uses file_get_contents() to read the webpage. Your server should be enabled allow_url_fopen() function otherwise you may need to use CURL to read the webpage.

For your convenience I have given a Demo here:


Add a Comment

Your email address will not be published. Required fields are marked *