Skip to content

Instantly share code, notes, and snippets.

@Gkiokan
Created January 8, 2018 10:04
Show Gist options
  • Save Gkiokan/48faa4a1df16054e9e60d4117fdd46f0 to your computer and use it in GitHub Desktop.
Save Gkiokan/48faa4a1df16054e9e60d4117fdd46f0 to your computer and use it in GitHub Desktop.
JSON full encode decode with UTF-8 support
/*
Data Class
* * * * * * *
Author: Gkiokan
Comment:
Encode and Decode Your String / Object / Array with utf-8 force.
*/
class Data {
// Encode
// @param $a Array Element to decode in JSON
public static function encode($a=[]){
$json = json_encode($a, JSON_UNESCAPED_UNICODE);
return $json;
}
// Decode
// @param $a JSON String
// @param $t Type of return (false = Array, true = Object)
public static function decode($a='', $t=false){
$obj = json_decode($a, $t, 512, JSON_UNESCAPED_UNICODE);
return $obj;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment