Removing duplicarte email addresses from existing list

4 posts by 2 authors in: Forums > CMS Builder
Last Post: December 21, 2012   (RSS)

Hi Jerry,

Is there a particular reason that your using output buffering to record the e-mail addresses into the array? I've modified your code so that it stores the e-mail addresses directly into an array:

<?php
$object = array();
foreach($client_uploadsRecords as $record){
foreach ($record['uploads'] as $upload{
if($upload['info5'] == 0 || !$upload['info5']){
//change e-mail address to lowercase.
$email = strtolower($record['email']) ;
//clean e-mail address
$email = preg_replace("/[ ]/", "", $email);
//If the e-mail address isn't already in the array, add it too it.
if(!in_array($email,$object)){
$object[] = $email;
}
}
}
}
//implode the output array.
$final_object = implode('; ', $output);
//... and then display it!
echo $final_object;
?>


So in this example I'm storing the e-mail address directly into the array, but only if the address isn't already in there.

Let me know if this doesn't work, or if you need something different.

Thanks!

Greg
Greg Thomas







PHP Programmer - interactivetools.com

Hi Greg,

I've been out of the loop for a few dayys. Thanks for responding. I would have answered earlier but with the new forum format, I never got an email that you responded.

No, there was no reason for using output buffering. I just couldn't think of another way.

Maybe this will solve the space issue.

I'll try it and post back.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By gkornbluth - December 21, 2012 - edited: December 21, 2012

Hi Greg,

After a few minor tweeks, like adding a close parenthesis after foreach ($record['uploads'] as $upload and changing $ouput to $object in final_object = implode('; ', $output); it worked like a charm with no more space issues.

Final code is below.

Thanks again,

BTW, Thanks for annotating the code so that I could understansd what was going on.

Jerry Kornbluth

$object = array();
foreach($client_uploadsRecords as $record){
foreach ($record['uploads'] as $upload){
if($upload['info5'] == 0 || !$upload['info5'])
{
//change e-mail address to lowercase.
$email = strtolower($record['email']) ;
//clean e-mail address
$email = preg_replace("/[ ]/", "", $email);
//If the e-mail address isn't already in the array, add it too it.
if(!in_array($email,$object)){
$object[] = $email;
}
}
}
}
//implode the output array.
$final_object = implode('; ', $object);
//... and then display it!
echo $final_object;
?>

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php