简体   繁体   English

在 laravel 中的 db 中显示 Summernote 内的图像

[英]Display images inside summernote from db in laravel

I'm working on a laravel project which should fetch content of home page (HTML Content) from database and display it inside Summernote rich text editor.我正在开发一个 laravel 项目,该项目应该从数据库中获取主页内容(HTML 内容)并将其显示在 Summernote 富文本编辑器中。 Summernote displays my HTML Content well but doesnot display images. Summernote 可以很好地显示我的 HTML 内容,但不显示图像。 On checking code displayed in summernote, It had replaced / character with "".在检查summernote中显示的代码时,它已将/字符替换为“”。 The same image gets displayed if pasted directly inside textarea and not fetched from dB.如果直接粘贴在 textarea 内而不是从 dB 中获取,则会显示相同的图像。 I tried some solutions found online and on stackoverflow but they didn't work for me.我尝试了一些在网上和 stackoverflow 上找到的解决方案,但它们对我不起作用。

 $(document).ready(function() { $('#summernote').summernote( { tabsize: 2, height: 400 }); });
 <form method="post"> <div> <textarea class="summernote" id="summernote" name="editordata"><div class="row-iconbox our-support-block"> {!!$cms_home->homepage_content!!} </textarea> </div> </form>

Digging deeper into / character being replaced by "" , MySQL had appended \ before every = while storing or updating hence the image address could not be found while loading HTML content from database.深入挖掘/""替换的字符,MySQL 在存储或更新时在每个=之前附加了\ ,因此在从数据库加载 HTML 内容时找不到图像地址。

sample HTML样品 HTML

<img src="/storage/img/icon1.svg" height="100" width="100"/>

HTML content after storing in dB HTML 存储后的内容以dB为单位

<img src=\"/storage/img/icon1.svg\" width=\"100\" height=\"100\" />

Solution解决方案

1. Check UTF encoding 1.检查UTF编码

Open Mysql in terminal and replace DATABASE_NAME, TABLE_NAME with your db_name and table_name respectively.在终端中打开 Mysql 并将 DATABASE_NAME、TABLE_NAME 分别替换为您的 db_name 和 table_name。

SELECT CCSA.character_set_name FROM information_schema.`TABLES` T,information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA WHERE CCSA.collation_name = T.table_collation AND T.table_schema = "DATABASE_NAME" AND T.table_name = "TABLE_NAME";

2. If Encoding is not utf8, alter database and table to utf8 encoding 2.如果Encoding不是utf8,将数据库和表改为utf8编码

see how to do this 看看怎么做

3. Add this code to your <head> in HTML 3. 将此代码添加到 HTML 中的<head>

 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM