Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test 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

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

Location

include/plugin_functions.php lines 211 to 257

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 17th November 2024 15:35 Europe/London time based on the source file dated 8th November 2024 11:50 Europe/London time.