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

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

报告相同问题?

悬赏问题

  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择