$v) $a[$k] = is_array($v) ? array_rmap($fn_name, $v) : call_user_func($fn_name, $v); return $a; } function json_escape_callback($v) // Internal function to escape certain characters before converting an array to JSON format { return str_replace(array("'", '}', '=', '>', '(', ')'), array("\\'", '!&125&!', '!&61&!', '!&62&!', '!&40&!', '!&41&!'), $v); } function convert_to_json($a) // Converts an array to JSON format. { if (!$a) return '{}'; return str_replace( array( ', }', '!&125&!', '!&61&!', '!&62&!', '!&40&!', '!&41&!'), array( ' }', '}', '=', '>', '(', ')'), implode(' ', explode("\n", preg_replace( array( '/^\s*array \(/im', '/^\s*([0-9]+) => $/im', '/^\s*([0-9]+) => (.*)$/im', '/^\s*(.+) => (.*)$/im', '/^\s*\)(,?)\s*$/im'), array( '{', '\'$1\':', '\'$1\': $2', '$1: $2', '}$1'), var_export(array_rmap('json_escape_callback', $a), true)) ))); } ?>