Make line break after semicolon;

2

I have a text file (word) composed of four pages with several e-mail addresses separated from each other by semicolons.

It's like this:

  

[email protected]; [email protected]; [email protected];
    [email protected]; [email protected]; [email protected];

I would like it to look like this:

  

[email protected];
    [email protected];
    [email protected];
    [email protected];
    [email protected];
    [email protected];

I believe you can do it using php where, it will be done a "read file" that for each; (semicolon) found will have a line break ...

I would like help getting this.

My code for now reads the file and prints the result on the screen ....

<?php
// Abre o Arquvio no Modo r (para leitura)
$arquivo = fopen ('emails.txt', 'r');

// Lê o conteúdo do arquivo 
while(!feof($arquivo))
{
//Mostra uma linha do arquivo
$linha = fgets($arquivo, 1024);
echo $linha.'<br />';
}

// Fecha arquivo aberto
fclose($arquivo);
?>
    
asked by anonymous 13.07.2015 / 17:53

2 answers

7

Would it be something like this?

str_replace(";",";<br>",texto);

It will replace all ; with ;<br> of texto .

    
13.07.2015 / 18:26
1

I have this complete method that does all the work to separate the email data:


 function setEmail($stringMail)
    {
        $nstringMail = preg_replace('/\;/',',', $stringMail);
        $nstringMail = preg_replace('/(.*)\<|\>(.*)/','', $stringMail);
        $nstringMail = preg_replace('/\v+/',',', $nstringMail);
        $nstringMail = preg_replace('/\t+/',',',  $nstringMail);
        $nstringMail = preg_replace('/\n+/',',', $nstringMail);
        $nstringMail = preg_replace('/\,\,/',',', $nstringMail);
        $nstringMail = preg_replace('/\s+/','', $nstringMail);

            $dataEmail = explode(',', $nstringMail);
           if (!empty($dataEmail)) {
               foreach ($dataEmail as $stringValue) {
                  if (filter_var($stringValue, FILTER_VALIDATE_EMAIL)) {
                         $emails[] = $stringValue;
                  }
               }
           }
        array_unique($emails);
        return $emails;
    }

$saida = setEmail('[email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected];');

echo "<pre>";
print_r($saida);

You can check the code in action here: link

    
13.07.2015 / 21:38