Skip to content

Commit

Permalink
Fix errors with UTF-8 encoding in the data.
Browse files Browse the repository at this point in the history
  • Loading branch information
eheikes committed Jan 17, 2016
1 parent 3b90c1e commit ebbd352
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion toreadapi.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<?php
$config = parse_ini_file('toread.ini');

// utf8ize written by Konstantin (http://stackoverflow.com/a/26760943).
function utf8ize($mixed) {
if (is_array($mixed)) {
foreach ($mixed as $key => $value) {
$mixed[$key] = utf8ize($value);
}
} else if (is_string ($mixed)) {
return utf8_encode($mixed);
}
return $mixed;
}

// Retrieves the categories.
function getCategories() {
global $dbh;
Expand Down Expand Up @@ -330,7 +342,7 @@ function deleteEntry() {
$data = $func();

header('Content-Type: application/json');
$encoded = json_encode($data);
$encoded = json_encode(utf8ize($data));
if (!$encoded) {
$data['links'] = array(array(
'id' => json_last_error(),
Expand Down

0 comments on commit ebbd352

Please sign in to comment.