Skip to content
This repository was archived by the owner on Jun 18, 2024. It is now read-only.

UTF-8 Encoding #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions includes/class.db-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,14 +438,38 @@ function error( $error, $code = '500' ) {

}

/**
* Converts strings in array to UTF-8
* Prevents Json from returning nulls values
* with incompatible characters.
**/
function utf8encoding($inArray) {

/* our return object */
$newArray = array();

/* step through inArray */
foreach($inArray as $key => $val) {
if(is_object( $val ) || is_array($val)) {
/* recurse on array elements */
$newArray[$key] = $this->utf8encoding($val);
} else {
$newArray[$key] = utf8_encode($val);
}
}

/* return utf8 encoded array */
return $newArray;
}

/**
* Output JSON encoded data.
* @todo Support JSONP, with callback filtering.
*/
function render_json( $data, $query ) {

header('Content-type: application/json');
$output = json_encode( $data );
$output = json_encode( $this->utf8encoding($data) );

// Prepare a JSONP callback.
$callback = $this->jsonp_callback_filter( $query['callback'] );
Expand Down Expand Up @@ -563,7 +587,7 @@ function object_to_xml( $array, $xml ) {

//simple key/value child pair
} else {
$xml->addChild( $key, $value );
$xml->addChild( $key, utf8_encode($value) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be $this->utf8_encode($value)?

}

}
Expand Down