I’m using CKeditor and I can’t use images with it. When I’m creating a post/article with it add images and such, everything works. However after I submit the article into the database it escapes the url and overall the syntax which will result in no image shown when I try to view it.
This is the img syntax in the editor:
<img alt="logo" src="/images/image.png" style="width: 250px; height: 183px; border-width: 2px; border-style: solid;" />
This is after the insertion function runs:
<img alt=\"logo\" src=\"/images/image.png\" style=\"width: 200px; height: 147px; border-width: 2px; border-style: solid;\" />
You get the gist of it, it escapes all the necessities so it doesn’t break the html. I did a few searches here and found something like html_entity_decode, which didn’t work.
How can I properly “un-escape” the syntax so the image shows up properly?
PS: Here’s the insertion and display script I use
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;
}
}
I tried html_entity_decode in the display script like $a = html_entity_decode($row['Body']); and then echo that or assign the row to a variable and decode it then. Maybe I did it wrong, I’m not sure.
Added stripslashes($output) to the display function, like this: