php-使用wangeditor实现数据库数据插入编辑器中

一、数据库查询

从数据库中查询需要展示的数据项$_POST['neirong'] = $row['neirong'];

二、js中取出变量,并对数据进行处理

var dataFromDatabase = '';

 htmlspecialchars_decode()是PHP中的一个函数,用于将字符串中的HTML实体转换回它们对应的字符。在HTML中,有些字符在文本中表示特殊意义,因此需要将其转换为对应的实体表示。例如,<表示小于号(<),>表示大于号(>),&表示&符号等。

例如:我现在的数据库中存的数据是<h1>标题1</h1><p>正文1</p> ,name这个函数就会转换为 

标题1

正文1

三、 在编辑器进行显示

通过html: dataFromDatabase,进行设置

//创建编辑器
const editor = createEditor({
    selector: '#editor-container',
    html: dataFromDatabase,
    config: editorConfig,
    mode: 'default', // or 'simple'
})

页面效果

php-使用wangeditor实现数据库数据插入编辑器中_第1张图片

页面完整代码



		' . ' ' . _('公告修改') . '
	

'; if (isset($_POST['UpdateMsg'])) { $InputError = 0; $i = 1; if (mb_strlen($_POST['title']) == 0) { $InputError = 1; prnMsg(_('标题不能为空!'), 'error'); $Errors[$i] = 'title'; $i++; } elseif ($_POST['neirong'] == '<p><br></p>') { $InputError = 1; prnMsg(_('内容不能为空!'), 'error'); $Errors[$i] = 'neirong'; $i++; } elseif ($_POST['msg_type'] == '<p><br></p>') { $InputError = 1; prnMsg(_('公告类型不能为空!'), 'error'); $Errors[$i] = 'msg_type'; $i++; } if ($InputError != 1) { $SQL_ClientSince = FormatDateForSQL($_POST['ClientSince']); if (isset($_POST['UpdateMsg'])) { //it is a new Customer $update_sql = " update message_board set title='" . $_POST['title'] . "' , msg_type='" . $_POST['msg_type'] . "' , neirong='" . strval($_POST['neirong']) . "' , enable_flag ='" . $_POST['enable_flag'] . "' , last_updated_by = '" . $_SESSION['UserID'] . "', last_update_date = '" . time() . "' where id='" . $_POST['Msgid'] . "' "; $ErrMsg = _('This customer could not be added because'); $update_result = DB_query($update_sql, $db, $ErrMsg); prnMsg(_('修改公告成功' . $OrderNum), 'success'); echo '
'; } } else { prnMsg(_('修改公告失败!'), 'error'); } } ?> 公告修改
*标题
公告类型 是否生效 创建人
*内容
 

你可能感兴趣的:(php,wangEditor,数据库,php,编辑器)