G
G
German Bezhev2020-04-19 18:02:33
PHP
German Bezhev, 2020-04-19 18:02:33

Problem with encoding when parsing and writing to the database (PHP)?

There is a task to parse goods from the site into the database (mariadb, database encoding utf8mb4). Using JS, we get a JSON file with UTF-8 encoding. Site in Russian. The code that writes to the file:

let productString = JSON.stringify(productArr);
    let link = document.createElement('a');
    var txtData = 'data:text/plain;charset=utf-8,' + encodeURIComponent(productString);
    link.href = txtData;
    link.target = '_blank';
    link.download = 'filename.txt';
    link.click();


Reading from a file is done with the usual file_get_contents in PHP.
As a result, we get the following information in the database.

5e9c67f0a47d8316954796.jpeg

How to get Russian characters in the database?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Shvedov, 2020-04-19
@constintmid

Check the format for sending json data, check the connection format so that it is utf-8 and see if the document you use for JSON always has troubles like this, just do JSON.parse and everything will be ok

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question