{name:"\u0414\u0436\u0438\u0414\u0438\u0421\u0438 \u0421\u0435\u0440\u0432\u0438\u0441\u0435\u0437"}
$app = new \Slim\Slim();
//Company handle
$app->contentType('text/html; charset=utf-8');
function getConnection() {
$dbhost="";
$dbuser="";
$dbpass="";
$dbname="crm";
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname;charset=utf8", $dbuser, $dbpass);
$dbh->exec("set names utf8");
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $dbh;
}
public function to_json($data) {
if ($data === null) {
$data = [];
}
$isArray = true;
$keys = array_keys($data);
$prevKey = -1;
foreach ($keys as $key)
if (!is_numeric($key) || $prevKey + 1 != $key) {
$isArray = false;
break;
} else
$prevKey++;
unset($keys);
$items = array();
foreach ($data as $key => $value) {
$item = (!$isArray ? "\"$key\":" : '');
if (is_array($value))
$item .= $this->to_json($value);
elseif (is_null($value))
$item .= 'null';
elseif (is_bool($value))
$item .= $value ? 'true' : 'false';
elseif (is_string($value))
$item .= '"' . preg_replace('%([\\x00-\\x1f\\x22\\x5c])%e', 'sprintf("\\\\u%04X", ord("$1"))', $value) . '"';
elseif (is_numeric($value))
$item .= $value;
else
throw new Exception('Wrong argument.');
$items[] = $item;
}
return ($isArray ? '[' : '{') . implode(',', $items) . ($isArray ? ']' : '}');
}
function fix_json($str) {
return preg_replace_callback(
'/\\\\u([0-9a-f]{4})/i',
function ($matches) {
$sym = mb_convert_encoding(
pack('H*', $matches[1]),
'UTF-8',
'UTF-16'
);
return $sym;
},
$str
);
}