Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utf8_decode is deprecated as of PHP8.2 (and probably wrong too) #9

Open
divinity76 opened this issue Feb 24, 2023 · 0 comments
Open

Comments

@divinity76
Copy link
Collaborator

first off, utf8_decode() is deprecated as of PHP8.2, and you should use

mb_convert_encoding($str, 'utf-8', 'ISO-8859-1')

instead,

second, utf8_decode converts data from ISO-8859-1 to UTF-8,
which means that if your XML document is not encoded with ISO-8859-1, the function

    /**
     * Replaces all html entities into its original symbols.
     * 
     * @param string $content
     * @return string
     */
    public function convertEntities($content)
    {
        $table = array_map('utf8_encode', array_flip(
            array_diff(
                get_html_translation_table(HTML_ENTITIES), 
                get_html_translation_table(HTML_SPECIALCHARS)
            )
        ));
        return preg_replace('/&#[\d\w]+;/', '', strtr($content, $table));
    }

doesn't even make sense, and is likely to corrupt UTF-8 XMLs..

divinity76 added a commit to divinity76/php-fast-xml-parser that referenced this issue Feb 24, 2023
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

No branches or pull requests

1 participant