1

我对 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>
4

1 回答 1

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>
于 2013-10-01T21:14:52.473 回答