52 dol_syslog(
"For better performance, enable the native json in your PHP", LOG_WARNING);
55 if (is_object($elements)) {
56 foreach ($elements as $key => $value) {
60 $num = count($elements);
65 if (is_numeric(key($elements)) && key($elements) == 0) {
67 $keysofelements = array_keys($elements);
69 for ($i = 0, $last = ($num - 1); $i < $num; $i++) {
70 if (!isset($elements[$keysofelements[$i]])) {
73 if (is_array($elements[$keysofelements[$i]]) || is_object($elements[$keysofelements[$i]])) {
74 $output .= json_encode($elements[$keysofelements[$i]]);
76 $output .=
_val($elements[$keysofelements[$i]]);
88 $tmpelements = array();
89 if (is_array($elements)) {
90 $tmpelements = $elements;
92 if (is_object($elements)) {
93 $tmpelements = get_object_vars($elements);
95 foreach ($tmpelements as $key => $value) {
96 $output .=
'"'.$key.
'":';
97 if (is_array($value)) {
98 $output .= json_encode($value);
100 $output .=
_val($value);
122 if (is_string($val)) {
125 $strlen_var = strlen($val);
131 for ($c = 0; $c < $strlen_var; ++$c) {
132 $ord_var_c = ord($val[$c]);
135 case $ord_var_c == 0x08:
138 case $ord_var_c == 0x09:
141 case $ord_var_c == 0x0A:
144 case $ord_var_c == 0x0C:
147 case $ord_var_c == 0x0D:
151 case $ord_var_c == 0x22:
152 case $ord_var_c == 0x2F:
153 case $ord_var_c == 0x5C:
155 $ascii .=
'\\'.$val[$c];
158 case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
163 case (($ord_var_c & 0xE0) == 0xC0):
166 $char = pack(
'C*', $ord_var_c, ord($val[$c + 1]));
169 $ascii .= sprintf(
'\u%04s', bin2hex($utf16));
172 case (($ord_var_c & 0xF0) == 0xE0):
175 $char = pack(
'C*', $ord_var_c, ord($val[$c + 1]), ord($val[$c + 2]));
178 $ascii .= sprintf(
'\u%04s', bin2hex($utf16));
181 case (($ord_var_c & 0xF8) == 0xF0):
184 $char = pack(
'C*', $ord_var_c, ord($val[$c + 1]), ord($val[$c + 2]), ord($val[$c + 3]));
187 $ascii .= sprintf(
'\u%04s', bin2hex($utf16));
190 case (($ord_var_c & 0xFC) == 0xF8):
193 $char = pack(
'C*', $ord_var_c, ord($val[$c + 1]), ord($val[$c + 2]), ord($val[$c + 3]), ord($val[$c + 4]));
196 $ascii .= sprintf(
'\u%04s', bin2hex($utf16));
199 case (($ord_var_c & 0xFE) == 0xFC):
202 $char = pack(
'C*', $ord_var_c, ord($val[$c + 1]), ord($val[$c + 2]), ord($val[$c + 3]), ord($val[$c + 4]), ord($val[$c + 5]));
205 $ascii .= sprintf(
'\u%04s', bin2hex($utf16));
210 return '"'.$ascii.
'"';
211 } elseif (is_int($val)) {
212 return sprintf(
'%d', $val);
213 } elseif (is_float($val)) {
214 return sprintf(
'%F', $val);
215 } elseif (is_bool($val)) {
216 return ($val ?
'true' :
'false');
222if (!function_exists(
'json_decode')) {
230 function json_decode($json, $assoc =
false)
247 dol_syslog(
"For better performance, enable the native json in your PHP", LOG_WARNING);
252 $strLength = strlen($json);
253 for ($i = 0; $i < $strLength; $i++) {
255 if (($json[$i] ==
'{') || ($json[$i] ==
'[')) {
257 } elseif (($json[$i] ==
'}') || ($json[$i] ==
']')) {
259 } elseif ($json[$i] ==
':') {
267 if ($json[$i] ==
'"' && $json[($i - 1)] !=
"\\") {
268 $comment = !$comment;
279 eval(
'$array = '.$out.
';');
287 if (!empty($array)) {
289 if (count($array) > 0) {
290 $object = (object) array();
292 foreach ($array as $key => $value) {
294 $object->{$key} = $value;
338 if (function_exists(
'mb_convert_encoding')) {
339 return mb_convert_encoding($utf16,
'UTF-8',
'UTF-16');
342 $bytes = (ord($utf16[0]) << 8) | ord($utf16[1]);
345 case ((0x7F & $bytes) == $bytes):
350 case (0x07FF & $bytes) == $bytes:
353 return chr(0xC0 | (($bytes >> 6) & 0x1F))
354 . chr(0x80 | ($bytes & 0x3F));
356 case (0xFFFF & $bytes) == $bytes:
359 return chr(0xE0 | (($bytes >> 12) & 0x0F))
360 . chr(0x80 | (($bytes >> 6) & 0x3F))
361 . chr(0x80 | ($bytes & 0x3F));
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!function_exists( 'json_decode')) dol_json_decode($json, $assoc=false)
Implement json_decode for PHP that does not support it Use json_encode and json_decode in your code !