【问题标题】:why I see html tag in php using tinymce textarea for input?为什么我在 php 中看到使用 tinymce textarea 输入的 html 标签?
【发布时间】:2016-02-26 17:11:00
【问题描述】:

TinyMCE 有问题。 当我将 TinyMCE textarea 内容(使用 jQuery)加载到我的数据库中,然后我在 php 页面上看到结果时,我看到了 html 标签...在图片中你可以找到一个示例。

HTML

<div class="container pt">
        <!-- +++++ Posts Lists +++++ -->
        <div class="row mt">
            <div class="col-lg-6 col-lg-offset-3 centered">
                <h3>MY BLOG</h3>
                <hr>
            </div>
        </div>
        <div id="white">
            <div class="container">
                <div class="row">
                    <div class="col-lg-8 col-lg-offset-2" id="menublog">

                    </div>
                </div><!-- /row -->
            </div> <!-- /container -->
        </div><!-- /white -->
    </div>

JQuery

$(document).ready(function() {
  $("#Insert").click(function(){
    event.preventDefault();
    var user = "2", titolo = $('#titolo').val(), articolo = tinyMCE.activeEditor.getContent({format : 'raw'}); 
    var id_immagine = $('#menuimmagini').val();
    alert(id_immagine);
    object = JSON.stringify({r: 'InsertPost', u: user, t: titolo, a: articolo, i:id_immagine});
    $.post("server.php", { js_object: object }, 
        function(msg){
            console.log(msg);
            if(msg)
            {
                alert("Post inserito con successo!");
                location.reload();
            }
        });
  });
});

输出查询

$(document).ready(function() {
    event.preventDefault();
    object = JSON.stringify({r: 'InitializeBlog'});
    $.post("servo.php", { js_object: object }, 
        function(response)
        {   
            var obj = jQuery.parseJSON(response);

            $.each( obj, function( index ) {
                    $('#menublog').append("<p><img class=\"img-circle\" src=\"assets/img/user.png\" width=\"50px\" height=\"50px\"> <ba>Salvo Bertoncini</ba></p> <p><bd>Posted on "+obj[index].date+"</bd></p> <h4>"+obj[index].title+"</h4> <p><img class=\"img-responsive\" src=\"show.php?id="+obj[index].idimmagine+"\"></p> "+obj[index].articles+" <p><a href=\"article.php?id="+obj[index].id+"\">Continue Reading...</a></p><hr>");
                });

        }
    );
});

【问题讨论】:

  • 你在哪里回显 PHP 中的输出?您可能正在使用 htmlentities 或类似的东西,而对于已知的 HTML 内容,您不想这样做。
  • post 已编辑,我使用 jquery 发送输出 html。
  • 已解决。我将解码用于 html 实体。也许,tinymce 会自动转换 html 实体中的文本区域内容。感谢您的宝贵时间。
  • 不要在你的问题/标题中加上“已解决”。如果您找到了解决方案,您可以自行回答您的问题并接受它。

标签: javascript php jquery html tinymce


【解决方案1】:

所有编辑器所见即所得将内容转换为 html 实体。例如,您应该使用这个库:

http://www.strictly-software.com/htmlencode

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-17
    • 1970-01-01
    • 1970-01-01
    • 2019-05-18
    • 2014-03-18
    • 1970-01-01
    • 1970-01-01
    • 2012-08-14
    相关资源
    最近更新 更多