Skip to content

Replace deprecated utf8_encode() in the CSV importer for PHP 8.2#485

Open
thisismyurl wants to merge 1 commit into
ThemeBoy:masterfrom
thisismyurl:fix/php82-utf8-encode-csv-import
Open

Replace deprecated utf8_encode() in the CSV importer for PHP 8.2#485
thisismyurl wants to merge 1 commit into
ThemeBoy:masterfrom
thisismyurl:fix/php82-utf8-encode-csv-import

Conversation

@thisismyurl

Copy link
Copy Markdown

PHP 8.2 housekeeping for the CSV importer. format_data_from_csv() calls utf8_encode(), which is deprecated as of PHP 8.2 and throws a deprecation notice on that import path when the source encoding isn't UTF-8.

mb_convert_encoding( $data, 'UTF-8', 'ISO-8859-1' ) is the documented one-to-one replacement (utf8_encode() is defined as exactly an ISO-8859-1 to UTF-8 conversion), so the converted bytes are identical. mbstring is effectively always present in a WordPress environment.

Thanks for keeping SportsPress going. It's an impressively deep plugin to maintain.

(full disclosure: AI helped me trace this and confirm the equivalence; the change and this note are mine.)

utf8_encode() is deprecated as of PHP 8.2 and fires a deprecation
notice on the CSV import path when the source encoding is not UTF-8.
mb_convert_encoding( $data, 'UTF-8', 'ISO-8859-1' ) is the documented
one-to-one replacement (utf8_encode is defined as ISO-8859-1 to UTF-8),
so the converted output is unchanged.
Copilot AI review requested due to automatic review settings July 14, 2026 13:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the SportsPress admin CSV importer to avoid PHP 8.2 deprecation notices by replacing the deprecated utf8_encode() call in the CSV data formatting path.

Changes:

  • Replace utf8_encode() with mb_convert_encoding() for ISO-8859-1 → UTF-8 conversion in format_data_from_csv().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 229 to 231
function format_data_from_csv( $data, $enc ) {
return ( $enc == 'UTF-8' ) ? $data : utf8_encode( $data );
return ( $enc == 'UTF-8' ) ? $data : mb_convert_encoding( $data, 'UTF-8', 'ISO-8859-1' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants