kankai
137
4
Laravel

Unicode problem, output strange words when in chinese

Posted 3 weeks ago by kankai

Hi guys,

I'm using summernote editor post content and upload image to my website. But i found out unicode problem and save strange words to my db.

常勇和舒森不仅是男神女神,也是超有才华的YouTuber哦!从高中毕业到大学毕业,两人都在彼此的身边!【高中到大å­

i suspect these code will affect to output but i'm not good with these

$detail=$request->input('detail');

$dom = new \DomDocument();

$dom->loadHtml($detail, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); 
        
$images = $dom->getElementsByTagName('img');

foreach($images as $k => $img){

            $data = $img->getAttribute('src');

            list($type, $data) = explode(';', $data);

            list(, $data)      = explode(',', $data);

            $data = base64_decode($data);

            $image_name= "/upload/" .time().$k.'.jpg';


            $path = public_path() . $image_name;

            file_put_contents($path, $data);

            $img->removeAttribute('src');

            $img->setAttribute('src', $image_name);

        }

        $detail = $dom->saveHTML();

Please sign in or create an account to participate in this conversation.