duanfu1945 2013-10-01 21:02
浏览 33

删除textarea中的HTML标记(基本CMS)

I am very new to PHP and started making a light weight CMS. I have stored all the body content in the database and the CMS calls it from the database and displays it in a text area to be edited. However I was wondering is there a way to make it display the text without HTML tags. I have tried the strip_tag function however when I hit save on my cms it saves without the html tags! how will I go about making it display the data from the database without HTML tags but when I save it, it will save with the HTML tags! Sorry if this question is not clear but it is quite difficult to explain. Here is my code so far working fine:

<?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>
  • 写回答

1条回答 默认 最新

  • dongsi0625 2013-10-01 21:14
    关注

    Change this:

    $pgcontent = $_POST['edit'];
    

    to:

    $pgcontent = strip_tags($_POST['edit']);
    

    And also change this:

    <textarea id="content" name="edit"><?php echo $pg_content; ?></textarea>
    

    to:

    <textarea id="content" name="edit"><?php echo strip_tags($pg_content); ?></textarea>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b