所见即所得编辑器转义图像网址


WYSIWYG editor escapes image url

我正在使用CKeditor,我不能使用它的图像。当我使用它创建帖子/文章时,添加图像等,一切正常。但是,在我将文章提交到数据库中后,它会转义 url 和整体语法,这会导致当我尝试查看它时不显示任何图像。

这是编辑器中的 img 语法:

<img alt="logo" src="/images/image.png" style="width: 250px; height: 183px; border-width: 2px; border-style: solid;" />

这是在插入函数运行之后:

<img alt='"logo'" src='"/images/image.png'" style='"width: 200px; height: 147px; border-width: 2px; border-style: solid;'" />

你明白它的要点,它逃脱了所有必需品,所以它不会破坏html。我在这里做了一些搜索,发现了类似 html_entity_decode 的东西,这不起作用。

如何正确"取消转义"语法,以便图像正确显示?

PS:这是我使用的插入和显示脚本

public function insert () {
    $sql = $this->db->prepare("INSERT INTO Content (Title, Body, category) VALUES (?, ?, ?)");
        $sql->bindParam(1, $_POST['title']);
        $sql->bindParam(2, $_POST['body']);
        $sql->bindParam(3, $_POST['category']);
        $sql->execute();
}
public function display ($id) {
    $sql = $this->db->query("SELECT Body FROM Content WHERE id='$id'");
    while ($row = $sql->fetch()) {
        echo $row;
    }
}

我尝试像$a = html_entity_decode($row['Body']);一样在显示脚本中html_entity_decode,然后回显该行或将行分配给变量并对其进行解码。也许我做错了,我不确定。

在显示函数中添加了条形斜杠($output),如下所示:

public function display ($id) {
    $sql = $this->db->query("SELECT Body FROM Content WHERE id='$id'");
    while ($row = $sql->fetch()) {
        //removes the extra slashes
        echo stripslashes($row); 
    }
}