4

I'm trying to get data from tags on a website by using the symfony crawler link this.

foreach ($tables as $table) {
    $response = $this->client->get($url, [
            'http_errors' => false,
    ]);

    $body = $response->getBody()->getContents();
    $crawler = new crawler($body);
    $version = $crawler->filter('tr > td');

    $i = 1;
    while (true) {
        if (something) {
            break;
        }
        $tableVersions[$table] = preg_split('/\r\n|\r|\n/', $version->eq($i + 1)->text());
        $i++;
    }
}
return $tableVersions;

In windows this works, the preg_split nicely splits the words that i wanted to split and put them each separately in an array.
When i print out $version->eq($i + 1)->text() in windows it looks like this:

word1
word2
word3

In linux it just puts all the strings without any delimiter in the first element of the array like this.

word1word2word3

it's the exact same code. So i'm guessing in windows the crawler returns new line feeds and in linux it doesn't? How should i then get a nice array of all the tags on a html page and then filter them?

Kasia Gogolek
  • 3,374
  • 4
  • 33
  • 50
jonasG
  • 41
  • 2
  • how are you "printing out" that value? what is the content of $version->eq($i + 1)->text() ? – Kasia Gogolek Mar 01 '18 at 14:45
  • As from somewhere in my brain: Linux and Windows treat `Line Breaks` differently. Maybe this gives you a direction to search further. – Henkersmann Mar 01 '18 at 14:45
  • @KasiaGogolek i just echo it and watch it in my cli. And the content of $version->eq($i + 1)->text() is just a long string that in my windows cli does a newline per word but doesn't in my Linux. – jonasG Mar 01 '18 at 14:54
  • have you tried the `PHP_EOL` constant instead of the other stuff? `PHP_EOL` holds the os-specific line break stuff so it would probably be correct on windows and linux. – Jakumi Apr 30 '18 at 20:18

0 Answers0