phpstringfileexplode

Access lines of a txt file by line index


Can anyone tell me why is this

$pole = explode("\n", file_get_contents('obce.txt'));

echo $pole[1];  //in obce.txt it is Test

different from

$pole[1] = "Test";
echo $pole[1];

For me, it seems to be the same thing.


Solution

  • Remember that in Windows the end of line caracters is "\r\n".

    Try:

    $pole = explode("\r\n", file_get_contents('obce.txt'));