Reputation: 1185
On my cakephp 3.6 project, in a page i am using ckeditor to save some content to my database. Then on my nextjs project i'm using an api to show it on frontend. But i am having some issues that seems like character encoding problem. An user copied some text from ms-word and paste it on my ckeditor then saved it. Here is the text that was copied:
Challеngе coins arе small and symbolic tokеns typically carriеd by mеmbеrs of various organizations and, most notably, in thе military.
But it is showing like this on frontend:
Challеngе coins arе small and symbolic tokеns typically carriеd by mеmbеrs of various organizations and, most notably, in thе military
This is the code that was used to save the data:
$blogs = $this->Blogs->newEntity();
$blogs = $this->Blogs->patchEntity($blogs, $data);
$blogs->content = preg_replace('/(.*?)/', '$1', $blogs->content);
$blogs->content = preg_replace('/<br\s*\/?>\s*(<br\s*\/?>)+/', '<br>', $blogs->content);
$blogs->content = preg_replace('/<div>\s*<\/div>/', '', $blogs->content);
$blogs->content = preg_replace('/<div>(.*?)<\/div>/', '$1', $blogs->content);
$blogs->content = preg_replace('/<\/div><br>/', '</div>', $blogs->content);
$blogs->content = preg_replace('/<br\s*\/?>\s*(<br\s*\/?>){2}$/', '', $blogs->content);
$this->Blogs->save($blogs);
I tried this code to convert the content before saving: $blogs->content = mb_convert_encoding($blogs->content, 'UTF-8', 'auto');
But its not working, and not seeing any other solutions may solve my problem. Anyone who can help me to solve this problem? Thank you.
Upvotes: 0
Views: 33