简体   繁体   English

PHP文本编码/解码(TinyMCE)

[英]PHP Text Encoding/Decoding (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. 我目前有一个页面,用户可以在其中使用TinyMCE编辑其页面。

The workflow is basic: User makes his edit -> submits -> AJAX call to SQL file -> SQL file updates in db. 工作流程是基本的:用户进行编辑->提交->对SQL文件的AJAX调用->数据库中的SQL文件更新。

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: 问题是我必须对输入进行编码/解码,因为当AJAX接收数据并在内容中具有&时,数据字符串将失败。.因此,这是我目前所拥有的:

<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: AJAX_edit_information.php包含一些检查,用于提交数据的代码为:

$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 当我看到文本时,我得到了一些奇怪的字符,例如:%u0308,%u0301o,%u0301 ..现在是我的问题,我在过程中要监督什么。.谢谢

I fixed the problem.. 我解决了问题。

When declaring the TinyMCE editor you have an option: 声明TinyMCE编辑器时,您可以选择:

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

This option controls how entities/characters get processed by TinyMCE. 此选项控制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 有关更多信息, 请参见http : //www.tinymce.com/wiki.php/Configuration : entity_encoding

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM