E
E
entermix2015-10-07 23:59:32
PHP
entermix, 2015-10-07 23:59:32

How to read file in binary file contents for json encode?

Is it possible somehow to read the file in binary file contents, for subsequent writing to an array and serialization to json ?
I try file_get_contents, when I try json_encode, I get an error:

son_encode(): Invalid UTF-8 sequence in argument

Tried this function:
function file_get_contents_utf8($fn) {
    $content = file_get_contents($fn);
    return mb_convert_encoding($content, 'UTF-8',
        mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true));
}

Everything seems to be OK, but when the array is deserialized, I get 0 elements.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nazar Mokrinsky, 2015-10-08
@entermix

Why read in binary mode text file O_o?
Why convert anything if json_encode() always produces utf8 and json_decode() only understands utf8?
UPD: The solution is to use a separate table to store binary files, see comments below this answer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question