fork(4) download
  1. <?php
  2.  
  3. function setEmail($stringMail)
  4. {
  5. $nstringMail = preg_replace('/\;/',',', $stringMail);
  6. $nstringMail = preg_replace('/\v+/',',', $nstringMail);
  7. $nstringMail = preg_replace('/\t+/',',', $nstringMail);
  8. $nstringMail = preg_replace('/\n+/',',', $nstringMail);
  9. $nstringMail = preg_replace('/\,\,/',',', $nstringMail);
  10. $nstringMail = preg_replace('/\s+/','', $nstringMail);
  11.  
  12. $dataEmail = explode(',', $nstringMail);
  13. if (!empty($dataEmail)) {
  14. foreach ($dataEmail as $stringValue) {
  15. if (filter_var($stringValue, FILTER_VALIDATE_EMAIL)) {
  16. $emails[] = $stringValue;
  17. }
  18. }
  19. }
  20. array_unique($emails);
  21. return $emails;
  22. }
  23.  
  24. $saida = setEmail('exemplo1@email.com; exemplo2@email.com; exemplo3@email.com; exemplo4@email.com; exemplo5@email.com; exemplo6@email.com;');
  25.  
  26. //echo "<pre>";
  27. print_r($saida);
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
Array
(
    [0] => exemplo1@email.com
    [1] => exemplo2@email.com
    [2] => exemplo3@email.com
    [3] => exemplo4@email.com
    [4] => exemplo5@email.com
    [5] => exemplo6@email.com
)