src/JoliTypo/Fixer.php
private function fixContentEncoding($content)
    {
        if (!empty($content)) {
            // Little hack to force UTF-8
            if (false === strpos($content, '<?xml encoding')) {
                $hack = false === strpos(
                    $content,
                    '<body'
                ) ? '<?xml encoding="UTF-8"><body>' : '<?xml encoding="UTF-8">';
                $content = $hack.$content;
            }

            $encoding = mb_detect_encoding($content);
            $headPos = mb_strpos($content, '<head>');

            // Add a meta to the <head> section
            if (false !== $headPos) {
                $headPos += 6;
                $content = mb_substr($content, 0, $headPos).
                    '<meta http-equiv="Content-Type" content="text/html; charset='.$encoding.'">'.
                    mb_substr($content, $headPos);
            }

            $content = mb_convert_encoding($content, 'HTML-ENTITIES', $encoding);
        }

        return $content;
    }
private function fixContentEncoding($content)
    {
        if (!empty($content)) {
            // Little hack to force UTF-8
            if (false === strpos($content, '<?xml encoding')) {
                $hack = false === strpos(
                    $content,
                    '<body'
                ) ? '<?xml encoding="UTF-8"><body>' : '<?xml encoding="UTF-8">';
                $content = $hack.$content;
            }

            $encoding = mb_detect_encoding($content);
            $headPos = mb_strpos($content, '<head>');

            // Add a meta to the <head> section
            if (false !== $headPos) {
                $headPos += 6;
                $content = mb_substr($content, 0, $headPos).
                    '<meta http-equiv="Content-Type" content="text/html; charset='.$encoding.'">'.
                    mb_substr($content, $headPos);
            }

            $content = mb_convert_encoding($content, 'HTML-ENTITIES', $encoding);
        }

        return $content;
    }
private function fixContentEncoding ( $ content ) { if ( ! empty ( $ content ) ) { // Little hack to force UTF-8 if ( false === strpos ( $ content , '<?xml encoding' ) ) { $ hack = false === strpos ( $ content , '<body' ) ? '<?xml encoding="UTF-8"><body>' : '<?xml encoding="UTF-8">' ; $ content = $ hack . $ content ; } $ encoding = mb_detect_encoding ( $ content ) ; $ headPos = mb_strpos ( $ content , '<head>' ) ; // Add a meta to the <head> section if ( false !== $ headPos ) { $ headPos += 6 ; $ content = mb_substr ( $ content , 0 , $ headPos ) . '<meta http-equiv="Content-Type" content="text/html; charset=' . $ encoding . '">' . mb_substr ( $ content , $ headPos ) ; } $ content = mb_convert_encoding ( $ content , 'HTML-ENTITIES' , $ encoding ) ; } return $ content ; }
Convert the content encoding properly and add Content-Type meta if HTML document.

@see http://php.net/manual/en/domdocument.loadhtml.php#91513
@see https://github.com/jolicode/JoliTypo/issues/7

@param $content

@return string
Convert the content encoding properly and add Content - Type meta if HTML document .