Hi

I have the following text:

$t = "hello world
this is another sentence";

I would like to split it into two parts, one for each line.
I tried: $lines = explode('\n', $t);

but when I did the following:
echo count($lines);

I got: 1 and not 2

what could be the problem?
should the split be around '\n', '\n\r' ?

thanks

    PHP (unlike say C++) does not parse \n within single quotes as a special character sequence.
    You need to enclose it in double quotes.

    <?php
    $t = "hello world
    this is another sentence";
    $lines = explode("\n", $t);
    print_r($lines);
    ?>

    This assumes that the newline sequence is "\n", not "\r" or "\r\n"

      If the file is not opened in binary mode then PHP will automatically map \r\n to \n in DOS format text files and \r to \n in MAC format text files.

        Write a Reply...