![]() |
|
|
| Subject:
Remove duplicate emails - PHP
Category: Computers > Programming Asked by: vladuzca-ga List Price: $10.00 |
Posted:
06 Sep 2005 19:19 PDT
Expires: 06 Oct 2005 19:19 PDT Question ID: 565046 |
|
| Subject:
Re: Remove duplicate emails - PHP
Answered By: palitoy-ga on 07 Sep 2005 03:09 PDT Rated: ![]() |
Hello
Thank-you for your question.
The following script should do what you require. It uses a regular
expression to match email addresses in a string. These email
addresses are placed in an array from which duplicates are then
removed.
=====================================
$emails = "email1@domain.com email2@domain.com email1@domain.com
email1@domain.com email3@test.co.uk";
print $emails."<br />";
print remove_duplicates($emails);
function remove_duplicates($str) {
# match all email addresses using a regular expression and store them
# in an array called $results
preg_match_all("([\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7})",$str,$results);
# sort the results alphabetically
sort($results[0]);
# remove duplicate results by comparing it to the previous value
$prev="";
while(list($key,$val)=each($results[0])) {
if($val==$prev) unset($results[0][$key]);
else $prev=$val;
}
# process the array and return the remaining email addresses
$str = "";
foreach ($results[0] as $value) {
$str .= " ".$value;
}
return $str;
};
================================================
If you require any further assistance on this subject please ask for
clarification and I will do my best to respond swiftly. |
vladuzca-ga
rated this answer:
and gave an additional tip of:
$2.00
Quick answer and he/she took the time to comment the script! |
|
| Subject:
Re: Remove duplicate emails - PHP
From: palitoy-ga on 07 Sep 2005 03:53 PDT |
Thank-you for the rating, kind comments and tip - they are all appreciated. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
| Search Google Answers for |
| Google Home - Answers FAQ - Terms of Service - Privacy Policy |