Let's say I've got a string "blbl\nblbl etc"
. I know I should start at position $pos
. I've got to select everything to the end of the line. I can't use this:
substr($string, $pos, strpos($string, "\n", $pos))
Mac doesn't use \n
as a delimiter. What should I do?
It should be :
substr($string, $pos, ( strpos($string, PHP_EOL, $pos) ) - $pos);
You can try the PHP_EOL
constant:
substr($string, $pos, strpos($string, PHP_EOL, $pos));
It contains the end-of-line character sequence of the OS the script is running.
Pass the string through a function which replaces \r\n or \r with \n first. It's worth doing as a matter of course, unless you actually want to preserve platform specific line endings.
FWIW Mac's use \n now anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With