I
I
Ilya Plotnikov2013-02-08 12:54:33
PHP
Ilya Plotnikov, 2013-02-08 12:54:33

Miracles with BLOWFISH inside JSON

Here is my code:

   $message = mcrypt_ecb(MCRYPT_BLOWFISH, 12344532523532, $message, MCRYPT_ENCRYPT);
    $answer = array("message"=>$message, "code"=>$code);
    var_dump($answer);
    echo json_encode($answer);
    exit();


And here is the result

array(2) { 
    ["message"]=> string(24) "zС”Э»Пі^cptO«q[email protected]Юн " 
    ["code"]=> int(1) 
} 


{"message":null,"code":1}


Tell me, where do such miracles come from? json eats characters unknown to it?

Answer the question

In order to leave comments, you need to log in

7 answer(s)
S
Sardar, 2013-02-08
@ilyaplot

The JSON parser may fall silent if it cannot recognize the encoding. Especially in the encoded data at the end of the padding of \0, which is not text at all. Pack in base64.
What are you reading? In the browser?

I
Ivan Lissitzky, 2013-02-08
@janson

Tell me, where do such miracles come from? json eats characters unknown to it?

If Cyrillic and PHP 5.4 and above, add JSON_UNESCAPED_UNICODE.
If Cyrillic and PHP < 5.4 - see www.php.net/manual/ru/function.json-encode.php in the comments there is an implementation for PHP 5.3
Actually, json itself cannot eat anything.

I
Ivan Lissitzky, 2013-02-08
@janson

double. I'm sorry

I
Ivan Lissitzky, 2013-02-08
@janson

double. I'm sorry

I
Ivan Lissitzky, 2013-02-08
@janson

double. I'm sorry

Y
Yuri Popov, 2013-02-08
@DjPhoeniX

And if you do so?

echo json_encode($answer,JSON_UNESCAPED_UNICODE);

Y
Yuri Popov, 2013-02-08
@DjPhoeniX

/* double, habr laid down ... */

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question