Remove empty spaces Laravel + webscraping

Asked

Viewed 155 times

3

I’m performing a webscraping as follows:

$url = 'https://esaj.tjsp.jus.br/cpopg/show.do?processo.codigo=XXXXXXXX&processo.numero=XXXXXXX';
$client = new Client();
$crawler = $client->request('GET', $url);
$movimentacao = $crawler->filter('tbody td')->each(function ($node) {
    return  explode('Movimentação', $node->text())[0];
});

$descricao1 = explode('Juntada', $movimentacao[2]);
\Log::alert(trim($movimentacao[2]));
dd();

I am bringing the information I need, but if I apply a dd to analyse the information of $movimentacao[2], is displayed to me as follows:

inserir a descrição da imagem aqui

I tried to apply the trim and the str_replace, but without success. Someone would know a way to withdraw those empty spaces in an efficient way? Grateful

  • 2

    I saw that it has tabulation, I think you can remove the tabulation as follows: trim(preg_replace('/\t+/', '', $string)) or you can use this one: $string = preg_replace('/\s+/', '', $string);

  • He’s really taking away the tabs, but the spaces remain...

  • 1

    Even using this command here? $string = preg_replace('/\s+/', '', $string);

  • 1

    It was perfectly... practical and fast. Grateful

  • 1

    Accept my answer there :D

1 answer

4


Try using this command:

$string = preg_replace('/\s+/', '', $string);
  • I did it like this: php
trim(preg_replace('/\t+/', '', $string));
preg_replace('/\n+/', '', $string);



  • 1

    Thanks for the help, it worked perfectly

  • 2

    @In this case, you could do preg_replace('/[\t\n]+/', '', $string) - thus already remove \t and \n at once.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.