Last Updated: February 25, 2016
·
569
· edinella

Escape JSON string

function escapeJsonString($value) {
    return str_replace(
        array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c"),
        array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b"),
        $value
    );
}