The fastest easiest way to get it right.

json_encode_safe

NAME

json_encode_safe

FUNCTION

The PHP function json_encode_safe checks to see if current php version contains JSON functions. If it does, then encodes the data. Otherwise it outputs an error. Safe way to use json_encode because not all PHP setups have JSON functions.

INPUTS

string $data - the data to encode

SOURCE

function json_encode_safe($data) {
    // Package up the JSON
    if(function_exists('json_encode')) {
        return json_encode($data);
    }
    else {
        return '{ "error": ["No JSON function in this version of PHP!"] }';
    }
    return;
}

User Comments

There are no user comments yet on this page.


Add A Comment

Comments will not appear until after they are moderated. Comments are usually moderated within a few hours on weekdays, but may take longer on weekends and holidays.

Name or nickname: (This will appear with your comment)


Email (this will never be displayed)


Enter your comment here. Use [b] and [/b] for bold, [i] and [/i] for italic, and [pre] and [/pre] for code samples. All literal HTML and PHP that you enter will be escaped out and displayed as you enter it.


Home |  Documentation |  Download |  Credits |  Contact |  Login
Andromeda © Copyright 2004-2010, Licensed under the GPL Version 2