Problem/Motivation

PHP 8.2 notes that utf8_encode() and utf8_decode() are deprecated because they can introduce obscure bugs. More info here.

Steps to reproduce

Use of the functions are found in branch 7.x-2.x and below. 8.x and 3.x don't use these functions.

Proposed resolution

The functions convert strings between ISO-8859-1 (Also known as "Latin 1") and UTF-8 encodings. These functions do not attempt to detect the actual character encoding in a given text, and always convert character encodings between ISO-8859-1 and UTF-8, even if the source text is not encoded in ISO-8859-1.

So instead of assuming ISO-8859-1, it seems like the best approach is to first detect the encoding then to convert it.

Example:
mb_convert_encoding($item, "UTF-8", mb_detect_encoding($item));

Patch coming in a followup comment.

Issue fork imce-3410945

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

hargobind created an issue. See original summary.

hargobind’s picture

Attached patch uses the proposed resolution.

hargobind’s picture

StatusFileSize
new6.11 KB

Fix for accidental overwriting of string in last patch.

hargobind’s picture

Status: Active » Needs review

dineshkumarbollu made their first commit to this issue’s fork.

ufku’s picture

Status: Needs review » Closed (duplicate)
Related issues: +#3432074: PHP8.2: Deprecated utf8_encode()