Jump to content

Recommended Posts

Hello,

 

I have a list of EMAILS which I want to clean.

ex.

[email protected];

Adriano Gomes Benício <[email protected]>;

"[email protected]" <[email protected]>;

 

I would like to CLEAN the list and get ONLY the email address like this:

 

[email protected],

[email protected]

 

It means removing    /names/ < / > / " / ;/ and add a COMA after each email.

 

I have this code, but it doesnt clean ALL

 

$patterns = array();
$patterns[0] = '/;/';


$replacements = array();
$replacements[2] = ',<br>';


echo preg_replace($patterns, $replacements, $string);

 

any help ?

Link to comment
https://forums.phpfreaks.com/topic/239802-cleaning-a-string/
Share on other sites

I have found this script

$text = ' [email protected] ';

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));

 

How to I get ONLY the emails to be printed:

[email protected],

[email protected],

[email protected]

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/239802-cleaning-a-string/#findComment-1231815
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.