From 5bef436e4bb15edb3f42a6084ab26b1663e8bc2d Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 8 May 2012 21:07:18 +0200 Subject: [PATCH] json_encode for PHP < 5.2 --- htdocs/application/controllers/main.php | 2 + htdocs/application/helpers/json_helper.php | 58 ++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100755 htdocs/application/helpers/json_helper.php diff --git a/htdocs/application/controllers/main.php b/htdocs/application/controllers/main.php index 59628f4..93d68e0 100755 --- a/htdocs/application/controllers/main.php +++ b/htdocs/application/controllers/main.php @@ -204,6 +204,7 @@ class Main extends CI_Controller function index() { + $this->load->helper('json'); if (!$this->input->post('submit')) { @@ -369,6 +370,7 @@ class Main extends CI_Controller function view() { + $this->load->helper('json'); $this->load->model('pastes'); $check = $this->pastes->checkPaste(2); diff --git a/htdocs/application/helpers/json_helper.php b/htdocs/application/helpers/json_helper.php new file mode 100755 index 0000000..8fe3c02 --- /dev/null +++ b/htdocs/application/helpers/json_helper.php @@ -0,0 +1,58 @@ + $value) + { + $output_indexed[] = json_encode($value); + $output_associative[] = json_encode($key) . ':' . json_encode($value); + + if ($output_index_count !== NULL && $output_index_count++ !== $key) + { + $output_index_count = NULL; + } + } + + if ($output_index_count !== NULL) + { + return '[' . implode(',', $output_indexed) . ']'; + } + else + { + return '{' . implode(',', $output_associative) . '}'; + } + default: + return ''; // Not supported + + + } + } +}