[ACCEPTED]-Select from position to end of line in string-string

Accepted answer
Score: 18

It should be :

substr($string, $pos, ( strpos($string, PHP_EOL, $pos) ) - $pos);

0

Score: 8

You can try the PHP_EOL constant:

substr($string, $pos, strpos($string, PHP_EOL, $pos));

It contains the 2 end-of-line character sequence of the OS 1 the script is running.

Score: 2

Pass the string through a function which 4 replaces \r\n or \r with \n first. It's 3 worth doing as a matter of course, unless 2 you actually want to preserve platform specific 1 line endings.

FWIW Mac's use \n now anyway.

Score: 1

If you need to process each individual line 4 in the string you can always split the string 3 into a array. You can do this using preg_split() in 2 a way that will identify more than systems 1 end of line character.

$lines = preg_split("/\r\n|\n|\r/", $string);

More Related questions