php Deprecated: auto_detect_line_endings is deprecated

Sharing is caring!

If you have a piece of code that parser CSV files you may have used this code to instruct php to try to detect the lines because they are different between Windows and Linux/Unix/Mac operating systems.

ini_set("auto_detect_line_endings", true);

Solution how to fix Deprecated: auto_detect_line_endings

You can remove the line that sets that config setting or have a php version check e.g. if it's less than php 8.1

// In some cases (Windows/Linux) the line endings are not read correctly, so we'll hint php to detect the line endings.
if (version_compare(PHP_VERSION, '8.1.0', '<')) {
    $old_auto_detect_line_endings_flag = ini_get("auto_detect_line_endings");
    ini_set("auto_detect_line_endings", true);
}

if (version_compare(PHP_VERSION, '8.1.0', '<')) {
    ini_set("auto_detect_line_endings", $old_auto_detect_line_endings_flag); // restore previous value
}
Subscribe to our newsletter

Sharing is caring!

Leave a Comment

Your email address will not be published. Required fields are marked *

Free Online Store by Go359.com
The new new server is up and running. Enjoy!