V
V
VicTHOR2019-05-29 15:52:25
PHP
VicTHOR, 2019-05-29 15:52:25

How to encode THIS in json?

Array:

Array
(
    [options] => Array
        (
            [0] => <option [email protected]красный>@красный</option>
            [1] => <option [email protected]�������>@�������</option>
            [2] => <option value=��_��>��_��</option>
        )
)

I want:
json_encode($array);
Error:
Malformed UTF-8 characters, possibly incorrectly encoded

If you do serialize($array), there are no errors, but how to parse this string in JS into an object then?
a:1:{s:7:"options";a:3:{i:0;s:54:"<option [email protected]красный>@красный</option>";i:1;s:40:"<option [email protected]�������>@�������</option>";i:2;s:34:"<option value=��_��>��_��</option>";}}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FanatPHP, 2019-05-29
@FanatPHP

These simple strings should simply be written in plain utf-8 encoding.
Anticipating possible objections. No, not "I've been picking my nose here, and I believe that these are just strings already in utf-8 encoding", but actually be in utf-8 encoding.
Anticipating possible offers. Re-encoding - it will be gibberish. It is necessary to immediately receive in the desired encoding, from where these lines come from. Since the author suddenly decided to play the young partisan, he will look for the actual solution on his own.
After the author managed to beat out the testimony, it became possible to restore the picture of the incident.
R¤Rћ_RўRћ is UTF recoded to 1251.
Accordingly, back

echo mb_convert_encoding('ФО_ТО', "cp1251", "utf-8");

I
index0h, 2019-05-29
@index0h

Cast all lowercase elements to utf8, or use the option: JSON_UNESCAPED_UNICODE

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question