If you want to use auto_detect_line_endings, e.g. to recognize carriage return on a Classic Mac file, you must set it before calling fopen. You can then reset it to its original value. E.g,
$original = ini_get("auto_detect_line_endings");
ini_set("auto_detect_line_endings", true);
$handle = fopen($someFile, "r");
ini_set("auto_detect_line_endings", $original);
while (($line = fgets($handle)) !== false) {
echo "$line\n"; // etc
}
(Reference: https://bugs.php.net/bug.php?id=63341&edit=2)
Keep in mind also that Mac OS X bash does not handle carriage returns well, so if it seems like your code is not working when testing from the command line, redirect your output to a file and then try looking at that. On my system, doing it directly on the command line only showed the last line (with or without this setting turned on).
Also note that this will not do what you want if you have a file with mixed line endings (!). If you really care about that case, you have to do something else, like run the file through a translation first and then read it.