douyinglan2599 2013-04-12 16:23
浏览 119
已采纳

PHP文本编码/解码(TinyMCE)

I have been struggling with this process for a while so I could use some help.

I currently have a page where the user can edit his page using TinyMCE.

The workflow is basic: User makes his edit -> submits -> AJAX call to SQL file -> SQL file updates in db.

The problem is that I have to encode/decode the input because when AJAX recieves the data and haves & in the content the data string will fail.. So this is what I have currently:

<script>
$(document).ready(function() {
    $('#edit').click(function () {
        var content = escape(tinyMCE.activeEditor.getContent());
        $.ajax({
            url: "AJAX_edit_information.php", 
            type: "POST",
            data: "content="+content,     
            success: function (msg) {
                //alert('blabla..');
            }       
        });
    });
}); 

The AJAX_edit_information.php contains a few checks and the code which is being used to submit the data is:

$inhoud = html_entity_decode(stripslashes($_POST['content']));
$query = "UPDATE informatie SET inhoud='$inhoud' WHERE id='1'";
$result = mysql_query($query);

Most of the things I tested works so far, except the wierd characters which were encoded.

On the page where i pull the data I have the following code:

$query = "SELECT * FROM informatie";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo html_entity_decode(stripslashes($row['inhoud']));

When I see the text, i get wierd characters like: %u0308, %u0301o, %u0301.. Now is my question, what am I overseeing in my process.. Thanks

  • 写回答

1条回答 默认 最新

  • duanduo0520 2013-04-12 17:01
    关注

    I fixed the problem..

    When declaring the TinyMCE editor you have an option:

    tinyMCE.init({
            ...
            entity_encoding : "raw"
    });
    

    This option controls how entities/characters get processed by TinyMCE. The value can be set as shown in Encoding Types below.

    For more information view: http://www.tinymce.com/wiki.php/Configuration:entity_encoding

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?