我需要帮助,请我需要一些帮助。我尝试在我的网页中使用 tinyeditor jquery,编辑器的内容成功提交到数据库但带有 html 标记。现在,当我尝试从数据库中检索数据并将其显示在另一个页面上时,它会将内容与所有 html 标签一起带出。请问我该如何更正它以显示为格式化文本?谢谢。
使用的 tinyeditor 脚本
<script>
new TINY.editor.edit('editor',{
id:'input', // (required) ID of the textarea
width:584, // (optional) width of the editor
height:175, // (optional) heightof the editor
cssclass:'te', // (optional) CSS class of the editor
controlclass:'tecontrol', // (optional) CSS class of the buttons
rowclass:'teheader', // (optional) CSS class of the button rows
dividerclass:'tedivider', // (optional) CSS class of the button diviers
controls:['bold', 'italic', 'underline', 'strikethrough', '|', 'subscript', 'superscript', '|', 'orderedlist', 'unorderedlist', '|' ,'outdent' ,'indent', '|', 'leftalign', 'centeralign', 'rightalign', 'blockjustify', '|', 'unformat', '|', 'undo', 'redo', 'n', 'font', 'size', 'style', '|', 'image', 'hr', 'link', 'unlink', '|', 'print'], // (required) options you want available, a '|' represents a divider and an 'n' represents a new row
footer:true, // (optional) show the footer
fonts:['Verdana','Arial','Georgia','Trebuchet MS'], // (optional) array of fonts to display
xhtml:true, // (optional) generate XHTML vs HTML
cssfile:'style.css', // (optional) attach an external CSS file to the editor
content:'starting content', // (optional) set the starting content else it will default to the textarea content
css:'body{background-color:#ccc}', // (optional) attach CSS to the editor
bodyid:'editor', // (optional) attach an ID to the editor body
footerclass:'tefooter', // (optional) CSS class of the footer
toggle:{text:'source',activetext:'wysiwyg',cssclass:'toggle'}, // (optional) toggle to markup view options
resize:{cssclass:'resize'} // (optional) display options for the editor resize
});
</script>
和
<script>
var editor = new TINY.editor.edit('editor', {
id: 'tinyeditor',
width: 500,
height: 175,
cssclass: 'tinyeditor',
controlclass: 'tinyeditor-control',
rowclass: 'tinyeditor-header',
dividerclass: 'tinyeditor-divider',
controls: ['bold', 'italic', 'underline', 'strikethrough', '|', 'subscript', 'superscript', '|',
'orderedlist', 'unorderedlist', '|', 'outdent', 'indent', '|', 'leftalign',
'centeralign', 'rightalign', 'blockjustify', '|', 'unformat', '|', 'undo', 'redo', 'n',
'font', 'size', 'style', '|', 'link', 'unlink', '|', 'print'],
footer: false,
fonts: ['Verdana','Arial','Georgia','Trebuchet MS'],
xhtml: true,
cssfile: 'custom.css',
bodyid: 'editor',
footerclass: 'tinyeditor-footer',
resize: {cssclass: 'resize'}
}
);
</script>
发布到数据库的表单
<form action="upload_poetry.php" method="post"
enctype="multipart/form-data">
<table width="100%" height="137" border="0" cellpadding="5" cellspacing="5">
<tr>
<td align="right" valign="top"><strong>Poem:</strong></td>
<td>.
<label for="tinyeditor"></label>
<textarea name="tinyeditor" id="tinyeditor" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="button" id="button" value="Submit" onclick="editor.post()"/></td>
</tr>
</table>
</form>
用于插入数据库的代码
<?php
include ('config.php');
$poem=$_POST['tinyeditor'];
$sql= "insert into poetry ( poem)values('$poem')";
$query=mysqli_query($dbC, $sql) or die(mysqli_error());
if ($query){
$msg = "Entry submitted pending Admin approval";
header("location:poem.php?msg=$msg");
}
else{$msg = "Not submitted Please retry";
header("location:poem.php?msg=$msg");}
?>
用于从数据库中检索的代码
<?php
include('config.php');
if (isset($_GET['id'])){
$id = $_GET['id'];
$sql = "SELECT * FROM poetry where title_id=$id";
$query = mysqli_query($dbC, $sql) or die(mysqli_error());
while($row = mysqli_fetch_array($query)){
$poem = $row['poem'];
}
?>
<table width="50%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td><strong>Poem:</strong></td>
<td colspan="4"><textarea id="" name="" ><?php echo $poem ?></textarea> </td>
</tr>
</table>
<?php
}
echo "<p><a href='index.php>Select an applicant to view his/her particulars</a></p>";
?>