What kind of data do you put into the editor? Just regular chinese text and images?
Jun 23, 2019
4
Level 3
Unicode problem, output strange words when in chinese
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 or to participate in this conversation.