Php 从TinyMCE中去除html_标记和额外的反斜杠<;textarea>;

Php 从TinyMCE中去除html_标记和额外的反斜杠<;textarea>;,php,sql-update,tinymce,Php,Sql Update,Tinymce,我正在用自己的CMS更新博客文章,CMS内置于PHP,并在XAMPP上本地运行。我已经下载了TinyMCE的源文件,TinyMCE是一个WYSIWYG插件,用于添加和编辑帖子。编辑工作得很好。除一个问题外,它按预期检索和提交数据;textarea标记中提交的内容(按类名包括TinyMCE对象)在实际的博客文章显示中包含额外的反斜杠和html标记。例如,文本行 这就是CSS(层叠样式表)的用武之地。这是一种设置页面内容格式的语言,可以设置所有文本、背景、图像、边框等的样式 放入文本区域后,返回并显

我正在用自己的CMS更新博客文章,CMS内置于PHP,并在XAMPP上本地运行。我已经下载了TinyMCE的源文件,TinyMCE是一个WYSIWYG插件,用于添加和编辑帖子。编辑工作得很好。除一个问题外,它按预期检索和提交数据;textarea标记中提交的内容(按类名包括TinyMCE对象)在实际的博客文章显示中包含额外的反斜杠和html标记。例如,文本行

这就是CSS(层叠样式表)的用武之地。这是一种设置页面内容格式的语言,可以设置所有文本、背景、图像、边框等的样式

放入文本区域后,返回并显示

这就是CSS(层叠样式表)的作用所在。这是一种设置页面内容格式和所有文本、背景、图像、边框等样式的语言。\r\n

这就是我困惑的地方

我先清理数据,然后将其作为mysqli语句中的参数绑定。我通过在functions.php中定义的clean()函数来运行我想要清理的任何数据。这不应该解决这个问题吗(到目前为止,在TinyMCE之前一直如此)。帖子内容清理提交流程如下:

functions.php

    function clean($param){

     global $connection;

     $cleaned = mysqli_real_escape_string($connection, trim(strip_tags($param)));

    return cleaned; 

    }
editPost.php,从中我省略了一些原始表单标记。只包括处理提交表单数据的php、表单的开头、包含post内容的代码块、提交按钮和表单的结尾。否则你们会盯着很多与问题无关的东西

    <?php

    if(isset($_POST['update_post'])) **{**

    $post_author = clean($_POST['post_author']);
    $post_title = clean($_POST['post_title']);
    $post_category_id = clean($_POST['post_category_id']);
    $post_category = clean($_POST['post_category']);
    $post_status = clean($_POST['post_status']);
    $post_image = $_FILES['post_image']['name'];
    $post_image_temp = $_FILES['post_image']['tmp_name'];
    $post_tags = clean($_POST['post_tags']);
    $post_content= clean($_POST['post_content']);
    $post_comment_count = clean($_POST['post_comment_count']);
    $post_date = clean($_POST['post_date']);

    $query = "UPDATE posts SET post_title = ?, post_category_id = ?, post_date = ?, post_author = ? , post_status = ?, post_tags = ?, post_content = ?, post_image = ? WHERE post_id = ?";  

    date_default_timezone_set('America/Los_Angeles');
    $now = date('Y-m-d');

 $stmt = mysqli_stmt_init($connection);
 mysqli_stmt_prepare($stmt, $query);
 mysqli_stmt_bind_param($stmt, 'sissssssi', $post_title, $post_category_id, $now, $post_author, $post_status, $post_tags, $post_content, $post_image, $post_id);


 mysqli_stmt_execute($stmt);
 mysqli_stmt_close($stmt);
 echo "<p class='bg-success'>Post Updated. <a href='../post.php?p_id={$get_post_id}'>View Post, </a> or <a href='posts.php'>Edit More Posts</a></p>";

    }

    ?>

     <form action="" method="post" enctype="multipart/form-data">
     <div class="form-group">
     <label for="post_content">Post Content </label>

     <textarea type="text" class="form-control tinymce" name="post_content" 
      cols="30" rows="10"><?php echo $post_content; ?>
     </textarea>
     </div>

     <div class="form-group">
     <input class="btn btn-primary" type="submit" name="update_post" value="Update Post">
 </div>

Dupe的可能副本用于PDO(IMO,这是更好的工具),但同样适用于mysqli。你是双重转义,这就是为什么你在存储的数据中有转义字符。非常感谢,miken32!你说得对。在这种情况下不需要转义。我拿出了clean(),效果很好。对不起,我对php还是比较陌生,几天前刚刚将数据库中的每个查询更新为准备好的语句。我想现在已经不需要clean()了,因为查询是这种格式的。非常感谢!很乐意帮忙。我支持我对PDO的推荐,而不是mysqli。更易于使用:无参数绑定,无需计算“s”和“i”,有用的方法(如
fetchAll
)和现代对象接口。谢谢您的建议。由于这个项目还很年轻,我可能会做出改变。计算参数并按顺序列出它们的数据类型绝对是一项烦人的任务。再次表示感谢!Dupe的可能副本用于PDO(IMO,这是更好的工具),但同样适用于mysqli。你是双重转义,这就是为什么你在存储的数据中有转义字符。非常感谢,miken32!你说得对。在这种情况下不需要转义。我拿出了clean(),效果很好。对不起,我对php还是比较陌生,几天前刚刚将数据库中的每个查询更新为准备好的语句。我想现在已经不需要clean()了,因为查询是这种格式的。非常感谢!很乐意帮忙。我支持我对PDO的推荐,而不是mysqli。更易于使用:无参数绑定,无需计算“s”和“i”,有用的方法(如
fetchAll
)和现代对象接口。谢谢您的建议。由于这个项目还很年轻,我可能会做出改变。计算参数并按顺序列出它们的数据类型绝对是一项烦人的任务。再次表示感谢!
    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/js/bootstrap.bundle.min.js"></script>
    <script type="text/javascript" src="https://www.google.com/jsapi"> 
    </script>
    <script src ="js/plugins/tinymce/jquery.tinymce.min.js"></script>
    <script src ="js/plugins/tinymce/tinymce.min.js"></script>
    <script type="text/javascript">
    tinymce.init({
        selector: "textarea.tinymce",
        plugins: [
            "advlist autolink link image lists print preview hr anchor pagebreak",
            "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media",
            "save table contextmenu directionality emoticons template paste textcolor"
            ],

        toolbar: "insertfile undo redo | styleselect | bold italic underline | 
         alignleft aligncenter alignright alignjustify | bullist numlist 
         outdent indent | link image | print preview media fullpage | 
         forecolor backcolor emoticons"



    });
    </script>
    <script src="js/scripts.js"></script>

    </body>
    </html>
    function clean($param){
    global $connection;
    $cleaned = mysqli_real_escape_string($connection, trim(strip_tags($param)));
    html_entity_decode($cleaned);
    htmlspecialchars_decode($cleaned);
    return $cleaned;

    }