Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

config_json_encode()

Description

A subset json_encode function that only works on $config arrays but has none
of the version-to-version variability and other "unusual" behavior of PHP's.
implementation.

whose elements are UTF-8 encoded strings, booleans, numbers or arrays
of such elements and whose keys are either numbers or UTF-8 encoded
strings.
capabilities to encode

Parameters

ColumnTypeDefaultDescription
$config
mixed $config a configuration variables array. This *must* be an array

Return

json encoded version of $config or null if $config is beyond our

Location

include/plugin_functions.php lines 200 to 246

Definition

 
function config_json_encode($config)
    {
    
$i=0;
    
$simple_keys true;
    foreach (
$config as $name => $value)
        {
        if (!
is_numeric($name) || ($name != $i++))
            {
            
$simple_keys false;
            break;
            }
        }
    
$output $simple_keys?'[':'{';
    foreach (
$config as $name => $value)
        {
        if (!
$simple_keys)
            {
            
$output .= '"' config_encode($name) . '":';
            }
        if (
is_string($value))
            {
            
$output .= '"' config_encode($value) . '"';
            }
        elseif (
is_bool($value))
            {
            
$output .= $value?'true':'false';
            }
        elseif (
is_numeric($value))
            {
            
$output .= strval($value);
            }
        elseif (
is_array($value))
            {
            
$output .= config_json_encode($value);
            }
        else
            {
            return 
NULL// Give up; beyond our capabilities
            
}
        
$output .= ', ';
        }
    if (
substr($output, -2) == ', ')
        {
        
$output substr($output0, -2);
        }
    return 
$output . ($simple_keys?']':'}');
    }

This article was last updated 30th November 2020 10:35 Europe/London time based on the source file dated 9th October 2020 10:20 Europe/London time.