我是PHP新手,开始制作轻量级CMS。我已将所有正文内容存储在数据库中,CMS从数据库中调用它并将其显示在要编辑的文本区域中。但是我想知道有没有办法让它显示没有HTML标签的文本。我已经尝试过strip_tag
函数但是当我点击我的cms保存它没有html标签就可以保存!如何在没有HTML标签的情况下显示数据库中的数据,但是当我保存它时,它将保存HTML标签!对不起,如果这个问题不明确,但很难解释。到目前为止,这是我的代码正常工作:
<?php include_once "includes/scripts.php"; ?>
<?php include_once "includes/connect.php";?>
<?php include_once "includes/cms_page_security.php";?>
<?php
$sql = "SELECT * FROM content WHERE id = '5'";
$result = mysql_query($sql, $connect);
$num= mysql_numrows($result);mysql_close();
$row = mysql_fetch_row($result);
$pg_content = $row['1'];
if (isset($_POST['saveChanges'])){
$pgcontent = $_POST['edit'];
$sql_query = ("UPDATE content SET cage_content= '$pgcontent' WHERE cage_content= '$pg_content'");
mysql_query($sql_query,$connect);
header('location: admin_cms_staff.php');
$feedback = "Updated successfully";
}
?>
<div id="cms_container"><br>
<h1>Staff Page<img src="images/three_column_grid_line.png" alt="line"></h1>
<form id="form1" name="form1" method="post">
<textarea id="content" name="edit"><?php echo $pg_content; ?></textarea>
<input type="submit" class="submit_edit" value="Save" name="saveChanges" onClick="alertFunction()">
</form>
<p class="logout_btn"><a href="admin_cms.php">Back</a></p>
<?php if(isset($_POST['saveChanges'])){
echo $feedback;}?>
</div><!--cms_container-->
<script>
function alertFunction()
{
var r=confirm("Do you want to save the changes you made to the page?");
if (r==true)
{
}
else
{
return;
}
}
</script>
</body>
</html>
答案 0 :(得分:1)
改变这个:
$pgcontent = $_POST['edit'];
为:
$pgcontent = strip_tags($_POST['edit']);
并且还改变了这个:
<textarea id="content" name="edit"><?php echo $pg_content; ?></textarea>
为:
<textarea id="content" name="edit"><?php echo strip_tags($pg_content); ?></textarea>