private function convertToHtmlEntities(string $htmlContent, string $charset = 'UTF-8'): string
    {
        set_error_handler(function () { throw new \Exception(); });

        try {
            return mb_convert_encoding($htmlContent, 'HTML-ENTITIES', $charset);
        } catch (\Exception $e) {
            try {
                $htmlContent = iconv($charset, 'UTF-8', $htmlContent);
                $htmlContent = mb_convert_encoding($htmlContent, 'HTML-ENTITIES', 'UTF-8');
            } catch (\Exception $e) {
            }

            return $htmlContent;
        } finally {
            restore_error_handler();
        }
    }
private function convertToHtmlEntities(string $htmlContent, string $charset = 'UTF-8'): string
    {
        set_error_handler(function () { throw new \Exception(); });

        try {
            return mb_convert_encoding($htmlContent, 'HTML-ENTITIES', $charset);
        } catch (\Exception $e) {
            try {
                $htmlContent = iconv($charset, 'UTF-8', $htmlContent);
                $htmlContent = mb_convert_encoding($htmlContent, 'HTML-ENTITIES', 'UTF-8');
            } catch (\Exception $e) {
            }

            return $htmlContent;
        } finally {
            restore_error_handler();
        }
    }
private function convertToHtmlEntities ( string $ htmlContent , string $ charset = 'UTF-8' ) : string { set_error_handler ( function ( ) { throw new \ Exception ( ) ; } ) ; try { return mb_convert_encoding ( $ htmlContent , 'HTML-ENTITIES' , $ charset ) ; } catch ( \ Exception $ e ) { try { $ htmlContent = iconv ( $ charset , 'UTF-8' , $ htmlContent ) ; $ htmlContent = mb_convert_encoding ( $ htmlContent , 'HTML-ENTITIES' , 'UTF-8' ) ; } catch ( \ Exception $ e ) { } return $ htmlContent ; } finally { restore_error_handler ( ) ; } }
Converts charset to HTML-entities to ensure valid parsing.
Converts charset to HTML - entities to ensure valid parsing .