Skip navigation
Help

drupal_json_encode

7 common.inc drupal_json_encode($var)

Converts a PHP variable into its JavaScript equivalent.

We use HTML-safe strings, i.e. with <, > and & escaped.

See also

drupal_json_decode()

Related topics

10 calls to drupal_json_encode()

File

drupal/includes/common.inc, line 4804
Common functions that many Drupal modules will need to reference.

Code

function drupal_json_encode($var) {
  // json_encode() does not escape <, > and &, so we do it with str_replace().
  return str_replace(array('<', '>', '&'), array('\u003c', '\u003e', '\u0026'), json_encode($var));
}