PHP Classes
elePHPant
Icontem

File: gefu.class.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of David Ferreira  >  Grab Emails From URL  >  gefu.class.php  >  Download  
File: gefu.class.php
Role: Class source
Content type: text/plain
Description: The class itself
Class: Grab Emails From URL
Retrieve e-mail addresses from pages
Author: By
Last change:
Date: 6 years ago
Size: 2,747 bytes
 

Contents

Class file image Download
<?php
/**
 * @name Grab Emails From URL [GEFU]
 * @version 1.0
 * @author David Sopas Ferreira <coder at davidsopas dot com>
 * @copyright 2008
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */

class gefu
{
   
// Regular expression to get valid email formats
   
private $email_regex = "/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/i";

   
// Regular expression to check vaid url format (credits to fqa)
   
private $url_regex = "^(https?|ftp)\:\/\/([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*(\:[0-9]{2,5})?(\/([a-z0-9+\$_-]\.?)+)*\/?(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?(#[a-z_.-][a-z0-9+\$_.-]*)?\$";

   
// Writable path for storing the emails list text files
   
private $path = "logs/";

    private
$dados = "";
    private
$counter = 0;

   
// Main function to grab the emails from a given url
   
public function grab($url)
    {
       
// Checks for a valid url format
       
if (eregi($this->url_regex, $url))
        {
           
$website = @file_get_contents($url);
           
// $pathfile will have the following format emails20080808-142823.txt
           
$pathfile = "$this->path/emails" . date("Ymd-His") . ".txt";
           
$filename = fopen($pathfile, 'a+');
           
preg_match_all($this->email_regex, $website, $matches);
           
// Clears duplicate emails on the array
           
$matches = array_unique($matches[0]);
            foreach (
$matches as $key => &$value)
            {
               
$this->dados .= $value . "\n";
               
$this->counter++;
            }
           
// Stores all the emails in the file
           
fwrite($filename, $this->dados);
           
fclose($filename);
            unset(
$value);
            if (
$this->counter > 0)
            {
                echo
"{$this->counter} emails were found and stored in the text file.";
            } else
            {
                echo
"Couldn't find any emails on the {$url}.";
            }
        } else
        {
            echo
"Provided {$url} has not a valid format.";
        }
    }
}
?>