php Deprecated: auto_detect_line_endings is deprecated

Do you need a temp WordPress site? Test it now!

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
}

Sharing is caring!

Do you need a temp WordPress site? Test it now!
This code shared in this post/site is provided "AS IS" without any warranties or guarantees of any kind. The authors and distributors of this code cannot be held responsible for any damage, data loss, or other issues that may arise from its use. It is strongly recommended that you test this code in a staging environment before deploying it to a live site. Always ensure you have proper backups and understand the implications of running this code on your WordPress installation. Use at your own risk.

Leave a Comment

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