From 53f4d605c42bf54068b38688d5174d70cf534bd6 Mon Sep 17 00:00:00 2001 From: Denis Ryabov Date: Wed, 23 Jul 2014 17:53:53 +0400 Subject: [PATCH] fix utf8 encoding --- twisterpost.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/twisterpost.php b/twisterpost.php index 963c4d3..a73b3c7 100644 --- a/twisterpost.php +++ b/twisterpost.php @@ -29,7 +29,12 @@ class TwisterPost $request->method = $method; $request->params = $params; - $request_json = json_encode($request); + if (defined('JSON_UNESCAPED_UNICODE')) { // PHP 5.4+: + $request_json = json_encode($request, JSON_UNESCAPED_UNICODE); + } else { // PHP 5.3: + $request_json = json_encode($request); + $request_json = preg_replace_callback('/\\\\u([0-9a-f]{4})/i', function($matches){return mb_convert_encoding(pack('H*', $matches[1]), 'UTF-8', 'UTF-16');}, $request_json); + } $ch = curl_init(); $url = "http://{$this->rpchost}:{$this->rpcport}/";