From c2cbd88d9e389833efdc2bf47bef52abde6e6abf Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 5 Nov 2011 00:47:22 +0100 Subject: [PATCH] Fix: Implement json_encode function for old PHP --- htdocs/lib/functions.lib.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index d8e22aed1dc..646c2f81e1a 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -35,6 +35,23 @@ if (! defined('DOL_DOCUMENT_ROOT')) define('DOL_DOCUMENT_ROOT', '..'); if (! defined('ADODB_DATE_VERSION')) include_once(DOL_DOCUMENT_ROOT."/includes/adodbtime/adodb-time.inc.php"); + +if (! function_exists('json_encode')) +{ + /** + * Implement json_encode for PHP that does not support it + * + * @param mixed $elements PHP Object to json encode + * @return string Json encoded string + */ + function json_encode($elements) + { + if (is_array($elements)) return '["' . join('","', $elements) . '"]'; + else return '"'.$elements.'"'; + } +} + + /** * This function output memory used by PHP and exit everything. Used for debugging purpose. */