str_replace with explode php

0
> A sua viagem  Ref. reserva:   5SPGW9  Check My Trip

    Data de emissão:    06 Novembro 2015    
 .
 .
Viajante    Mrs Ana Paula Monteiro Malfati      Agência INTERCAMBIO OPERADORA DE PROGRAMAS EDUC
Rua Dos Tres Irmaos, 625
Vila Progredior  Cep:05615-190
SAO PAULO
Telefone    (11) 3149-8199
Fax (11) 3149-8199
E-mail  [email protected]



 .


 .
  Sexta-feira 29 Janeiro 2016   

I am trying to separate this text into 3 blocks, but it is not accepting commands. I first change the dots by " " and then I explode in line breaks, but it does not work.

$dados = str_replace(".", " ", $dados);
$dados = explode("\n\n", $dados);

$dados is where I store this text.

    
asked by anonymous 10.11.2015 / 19:05

1 answer

1

First thing, use only one dot '.' will present several conflicts seen in your text has [Ref.] [.com.br] it would end up making the replacement in a wrong place.

As you just want to replace the dots with spaces and create three blocks you could could solve like this:

$foo = 'A sua viagem  Ref reserva:   5SPGW9  Check My Trip
        Data de emissão:    06 Novembro 2015
      ..
      Viajante Mrs Ana Paula Monteiro Malfati
      Agência INTERCAMBIO OPERADORA DE PROGRAMAS EDUC
      Rua Dos Tres Irmaos, 625
      Vila Progredior  Cep:05615-190
      SAO PAULO
      Telefone    (11) 3149-8199
      Fax (11) 3149-8199
      E-mail  [email protected]
      ..
      Sexta-feira 29 Janeiro 2016';

$blocos = explode("..", $foo);
echo $blocos[0];
echo $blocos[1];
echo $blocos[2];

I added two points in a row to avoid conflict.

See working at Ideone

    
10.11.2015 / 19:31