Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

config_encode()

Description

Utility function to encode the passed string to something that conforms to
the json spec for a string. Json doesn't allow strings with double-quotes,
backslashes or control characters in them. For double-quote and backslash,
the encoding is '\"' and '\\' respectively. The encoding for control
characters is of the form '\uxxx' where "xxx" is the UTF-8 4-digit hex
value of the encoded character.

Parameters

ColumnTypeDefaultDescription
$input
string $input the string that needs encoding

Return

an encoded version of $input

Location

include/plugin_functions.php lines 243 to 264

Definition

 
function config_encode($input)
    {
    
$output '';
    for (
$i 0$i strlen($input); $i++)
        {
        
$char substr($input$i1);
        if (
ord($char) < 32)
            {
            
$char '\\u' substr('0000' dechex(ord($char)),-4);
            }
        elseif (
$char == '"')
            {
            
$char '\\"';
            }
        elseif (
$char == '\\')
            {
            
$char '\\\\';
            }
        
$output .= $char;
        }
    return 
$output;
    }   

This article was last updated 19th March 2024 07:35 Europe/London time based on the source file dated 15th March 2024 17:00 Europe/London time.