0

I have some persian/farsi characters stored in a database for a multilingual website and I am creating a simple extension to export the content of this table into a text file.

The export works fine with normal english characters of the table, but the persian characters are exported in unicode i believe. This is how they are stored on the database: enter image description here

This is the function that I have to write the table to a file:

public function setData($data)
    {

        $handle = fopen($this->getFilename(), "w");
        fwrite($handle, $data);
        fclose($handle);

        header('Content-Type: application/octet-stream; charset=UTF-8');
        header('Content-Disposition: attachment; filename='.basename($this->getFilename()));
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($this->getFilename()));
        readfile($this->getFilename());

    }

$data is a string, another function converts all the rows and columns and puts them into a string.

How can I convert the data from how it is (in the picture above) into normal readable characters?

I apologize if this is a duplicate but I've tried many solutions online to try to convert this and none of them has worked so far.

Mahan_F
  • 7,839
  • 2
  • 14
  • 26
  • `json_encode(json_decode($that_data), JSON_UNESCAPED_UNICODE);` and/or just use that flag in the original encoding. But also make sure that your transport/display/encoding/decoding doesn't munge the data. https://stackoverflow.com/questions/279170/utf-8-all-the-way-through – Sammitch May 22 '18 at 17:58
  • Also, why are you writing out `$data` to disk just to call `readfile()` on it? Just print it out directly. – Sammitch May 22 '18 at 18:03

0 Answers0