Ad

How To Encode Polish Characters

- 1 answer

I have code thanks to whom use wysciwyg editor (and uploading photo correctly from editor). The part of this code looks like this

$detail=$request->input('description');
$dom = new \DomDocument();
$dom->loadHtml($detail, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$images = $dom->getElementsByTagName('img');

Generally this code works but instead of polish characters I have (sor example)

<p>sad s&nbsp; ads asd sa d as&Auml;&#133;&Aring;&#155;&Auml;&#135;&Atilde;&sup3;&Aring;&#130;&Aring;&frac14; sdas das das dsa d</p>

I tried use

{!! html_entity_decode($article->description, ENT_QUOTES, 'UTF-8') !!}

It doesn't work.

Ad

Answer

Try mb_convert_encoding and $dom->encoding = 'UTF-8';

            $dom = new \DOMDocument();
            $dom->substituteEntities = TRUE;
            $dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
            $dom->encoding = 'UTF-8';

And then just print out content in blade

{!! $article->description !!}}
Ad
source: stackoverflow.com
Ad