Reputation:
How do I do output HTML that comes back from database after it's been decoded back from html entities to HTML. I'm learning how to use Tinymce and I'm stuck. I can't echo the HTML because it just prints it in the page. Do I have to look on the DOM side with DOMDocument? I've seen this question asked on different sites but never answered clearly.Or maybe i'm such a newbie that the answer is right in front of me. Thanks!
<?php
$page_title = "Brian Aylward comedy website";
$current_page = "home";
include("site_admin/tinymce/shows/db.php");
doDB();
$get_contents_sql = "SELECT * FROM tinymce_contents";
$get_contents_res = mysqli_query($mysqli, $get_contents_sql)
or die(mysqli_error($mysqli));
if ($get_contents_res = mysqli_query($mysqli, $get_contents_sql)) {
while ($row = mysqli_fetch_assoc($get_contents_res)) {
$contents = $row['contents'];
$fill_block = html_entity_decode($contents);
}
}
mysqli_close($mysqli);
include_once'./includes/header.php'; ?>
<span id="mikemouth"></span>
<div id="jacket">
<h2 id="showtitle">LIVE DATES</h2>
<div id="shows">
<div class="shows_content">
<?php
//I want to output the HTML here but can't use echo $fill_block; since it will print
//the HTML in the webpage when I want it parsed as HTML.Does it make sense?
?>
Upvotes: 0
Views: 1445
Reputation: 836
If you stored the HTML in the database with htmlentities() then you'd need to use html_entity_decode() when printing it in the markup. Although I'd suggest that you don't store the HTML with the encoded tags in the first place.
Lets say that you stored the following HTML code in the database after passing it through htmlentities():
<a href="http://hello.com">hello</a>
If you print it you will get something like:
<a href="http://hello.com">hello</a>
To use it properly in TinyMCE you would need to pass it through html_entity_decode() which will produce the right markup.
Now lets say you have the following in the database:
<a href="http://hello.com">hello</a>
It will probably be stored looking like this:
<a href=\"http://hello.com\">hello</a>
You would need to use stripslashes() on it before sending it to the markup
Upvotes: 3