Unicode string in data (v2020)

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
gigakun
User
Posts: 99

Unicode string in data (v2020)

Post by gigakun »

Good Day all. Basically i'm doing a regular insert/update. The data was converted from a CKeditor field to JSON string.
So what's happending is in one column when the data is inserted/updated it's fine. In the problematic column, it appears the unicode strings are converted to their actual value
So all the \r\n and \u00a0 in the JSON string are coverterd actual line breaks and spaces into a broken JSON string and inserted into the table. This breaks the JSON when retreiving it as there shouldn't be any line breaks.
The both columns are a datatype of TEXT, same collation etc. I do a var_dump on the JSON string before it's inserted/updated and it's great it shows the unicode as normal but when it hits the DB it gets messed up. Works good on another column in the same table (But from a different page of the project but bascially same code) v2020. Thanks.


mobhar
User
Posts: 11660

Post by mobhar »

You may try to assign Raw property of the field to true in Page_Load server event of Add Page and/or Edit Page, for example:

$this->YourFieldName->Raw = true; // <-- adjust YourFieldName to your actual field name


arbei
User
Posts: 9286

Post by arbei »

gigakun wrote:

The data was converted from a CKeditor field to JSON string.

Did you mean you use CKEditor to input JSON string? You better use a text area instead, CKEditor may convert the data when you save.


gigakun
User
Posts: 99

Post by gigakun »

@mohbar I'll give that a try although the problem occurs when inserting/updating.
@arbei I don't type the JSON directly. whatever the text i input in the ckeditor field I then encode it to JSON in the row inserting/updating event and decode it back when necessary.


arbei
User
Posts: 9286

Post by arbei »

The first thing you should try is setting the Raw property to true.

In case it does not work:

gigakun wrote:

whatever the text i input in the ckeditor field I then encode it to JSON in the row inserting/updating event and decode it back when necessary.

  1. How did you encode and decode? You may post your code for discussion.
  2. What is the data type of the field?
  3. What is the charset of the table and the charset of the database? Are they both utf-8? (Note that JSON is utf-8.)

Post Reply