The problem reduces to counting \n characters, so is there a function that can do it on a huge strings, since explode() wastes too much memory.
\n