diff options
-rw-r--r-- | index.php | 37 |
1 files changed, 36 insertions, 1 deletions
@@ -2151,7 +2151,42 @@ function isTZvalid($continent,$city) | |||
2151 | } | 2151 | } |
2152 | return false; | 2152 | return false; |
2153 | } | 2153 | } |
2154 | 2154 | if (!function_exists('json_encode')) { | |
2155 | function json_encode($data) { | ||
2156 | switch ($type = gettype($data)) { | ||
2157 | case 'NULL': | ||
2158 | return 'null'; | ||
2159 | case 'boolean': | ||
2160 | return ($data ? 'true' : 'false'); | ||
2161 | case 'integer': | ||
2162 | case 'double': | ||
2163 | case 'float': | ||
2164 | return $data; | ||
2165 | case 'string': | ||
2166 | return '"' . addslashes($data) . '"'; | ||
2167 | case 'object': | ||
2168 | $data = get_object_vars($data); | ||
2169 | case 'array': | ||
2170 | $output_index_count = 0; | ||
2171 | $output_indexed = array(); | ||
2172 | $output_associative = array(); | ||
2173 | foreach ($data as $key => $value) { | ||
2174 | $output_indexed[] = json_encode($value); | ||
2175 | $output_associative[] = json_encode($key) . ':' . json_encode($value); | ||
2176 | if ($output_index_count !== NULL && $output_index_count++ !== $key) { | ||
2177 | $output_index_count = NULL; | ||
2178 | } | ||
2179 | } | ||
2180 | if ($output_index_count !== NULL) { | ||
2181 | return '[' . implode(',', $output_indexed) . ']'; | ||
2182 | } else { | ||
2183 | return '{' . implode(',', $output_associative) . '}'; | ||
2184 | } | ||
2185 | default: | ||
2186 | return ''; // Not supported | ||
2187 | } | ||
2188 | } | ||
2189 | } | ||
2155 | 2190 | ||
2156 | // Webservices (for use with jQuery/jQueryUI) | 2191 | // Webservices (for use with jQuery/jQueryUI) |
2157 | // eg. index.php?ws=tags&term=minecr | 2192 | // eg. index.php?ws=tags&term=minecr |