/** * @note: Convert non-UTF-8 characters into UTF-8 * Function taken from http://stackoverflow.com/a/19366999 * * @param $data * * @return array|string */ public static function encodeAsUTF8($data) { if (is_array($data)) { foreach ($data as $key => $value) { $data[$key] = Utility::encodeAsUTF8($value); } } else { if (is_string($data)) { return utf8_encode($data); } } return $data; }
function encodeAsJSON($data) { $json = json_encode(Utility::encodeAsUTF8($data)); if ($json === false) { showApiError(201); } return $json; }