PHP forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.
November 2024
SunMonTueWedThuFriSat
     12
3456789
10111213141516
17181920212223
24252627282930

Calendar Calendar

Latest topics
» Kabaddi, Kabaddi, Kabaddi, Kabaddi......PHP?
PHP Script to Extract Email Address from any text EmptyFri Jul 22, 2011 1:37 pm by shyamsunder

» Thousands of Free PHP Scripts Recommended
PHP Script to Extract Email Address from any text EmptyWed May 18, 2011 10:33 am by bizboy12

» PHP form validation problem?
PHP Script to Extract Email Address from any text EmptyWed Jan 12, 2011 1:25 pm by simy202

» string wrap
PHP Script to Extract Email Address from any text EmptySat Aug 02, 2008 2:06 pm by scvinodkumar

» retrieving current date rows
PHP Script to Extract Email Address from any text EmptyTue Jul 15, 2008 3:25 am by scvinodkumar

» number in words
PHP Script to Extract Email Address from any text EmptyTue Apr 29, 2008 3:10 pm by scvinodkumar

» Simple PHP Form Field Generator
PHP Script to Extract Email Address from any text EmptyFri Apr 25, 2008 12:28 pm by scvinodkumar

» PHP password generator
PHP Script to Extract Email Address from any text EmptyFri Apr 18, 2008 7:24 pm by scvinodkumar

» PHP Script to Extract Email Address from any text
PHP Script to Extract Email Address from any text EmptyFri Apr 18, 2008 7:18 pm by scvinodkumar

Search
 
 

Display results as :
 


Rechercher Advanced Search

Affiliates
free forum
 


Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

PHP Script to Extract Email Address from any text

Go down

PHP Script to Extract Email Address from any text Empty PHP Script to Extract Email Address from any text

Post  scvinodkumar Fri Apr 18, 2008 7:18 pm

$text = ' email@domain.com ';

function parseTextForEmail($text) {
$email = array();
$invalid_email = array();

$text = ereg_replace("[^A-Za-z._0-9@ ]"," ",$text);

$token = trim(strtok($text, " "));

while($token !== "") {

if(strpos($token, "@") !== false) {

$token = ereg_replace("[^A-Za-z._0-9@]","", $token);

//checking to see if this is a valid email address
if(is_valid_email($email) !== true) {
$email[] = strtolower($token);
}
else {
$invalid_email[] = strtolower($token);
}
}

$token = trim(strtok(" "));
}

$email = array_unique($email);
$invalid_email = array_unique($invalid_email);

return array("valid_email"=>$email, "invalid_email" => $invalid_email);

}

function is_valid_email($email) {
if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$",$email)) return true;
else return false;
}

var_dump(parseTextForEmail($text));

scvinodkumar
Admin

Posts : 40
Join date : 2008-01-30

https://solutions.aforumfree.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum