Services_JSON::reduce_string()publicWP 1.0

Deprecated from version 5.3.0. It is no longer supported and can be removed in future releases. Use PHP native JSON extension instead.

reduce a string by removing leading and trailing comments and whitespace

Method of the class: Services_JSON{}

Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.

No Hooks.

Return

String. string value stripped of comments and whitespace

Usage

$Services_JSON = new Services_JSON();
$Services_JSON->reduce_string( $str );
$str (required)
-

Changelog

Deprecated since 5.3.0 Use the PHP native JSON extension instead.

Services_JSON::reduce_string() code WP 6.5.4

function reduce_string($str)
{
    _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );

    $str = preg_replace(array(

            // eliminate single line comments in '// ...' form
            '#^\s*//(.+)$#m',

            // eliminate multi-line comments in '/* ... */' form, at start of string
            '#^\s*/\*(.+)\*/#Us',

            // eliminate multi-line comments in '/* ... */' form, at end of string
            '#/\*(.+)\*/\s*$#Us'

        ), '', $str);

    // eliminate extraneous space
    return trim($str);
}