I have saved a table created inside TinyMCE to the database. When I fetch the content using PHP, it gives too many <br> before the table. If I remove nl2br, then it shows the perfect result but I need nl2br because there may be paragraphs in my text as well.
Database entry:
<p><table style="border-collapse: collapse; width: 100%; border-style: solid;" border="1">
<tbody>
<tr style="height: 21px;">
<td style="width: 50%; text-align: left; height: 21px;">12th Arts</td>
<td style="width: 50%; text-align: left; height: 21px;">31</td>
</tr>
</tbody>
</table></p>
PHP Code to fetch and show
echo '<h2><span>'. htmlspecialchars_decode($pagetitle). '</span></h2>';
echo '<p class="text-justify">'. nl2br(htmlspecialchars_decode($paracolumns)). '</p>';
Code to render TinyMCE
tinymce.init({
selector:'textarea.mytextarea',
plugins: [
"advlist autolink lists link charmap anchor",
"searchreplace fullscreen",
"insertdatetime contextmenu paste ",
"table"
],
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link",
table_toolbar: 'tableprops tabledelete | tableinsertrowbefore tableinsertrowafter tabledeleterow | tableinsertcolbefore tableinsertcolafter tabledeletecol',
table_appearance_options: false,
menubar: true,
min_height: 300,
max_height: 500,
statusbar: false,
forced_root_block : false,
force_br_newlines : true,
force_p_newlines : false,
mobile: {
theme: 'silver',
min_height: 300,
max_height: 500,
menubar: false,
statusbar: false
/*
height: 300,
max_height: 500,
max_width: 500,
min_height: 400,
statusbar: false,
toolbar: false,
plugins: ["autosave", "lists", "autolink"]
*/
}
})
Output I get
question from:
https://stackoverflow.com/questions/65933547/table-created-using-tinymce-gives-too-many-hidden-newline-elements 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…