Sino
Sino

Reputation: 990

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.

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

Upvotes: 2

Views: 4027

Answers (1)

Sino
Sino

Reputation: 990

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

Upvotes: 6

Related Questions