drupal_json_encode

Versions
7
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()

▾ 6 functions call drupal_json_encode()

ajax_render in includes/ajax.inc
Render a commands array into JSON and exit.
drupal_get_js in includes/common.inc
Returns a themed presentation of all JavaScript code for the current page.
drupal_json_output in includes/common.inc
Return data in JSON format.
system_page_build in modules/system/system.module
Implement hook_page_build().
upload_js in modules/upload/upload.module
Menu-callback for JavaScript-based uploads.
_locale_rebuild_js in includes/locale.inc
(Re-)Creates the JavaScript translation file for a language.

Code

includes/common.inc, line 4369

<?php
function drupal_json_encode($var) {
  // json_encode() does not escape <, > and &, so we do it with str_replace().
  return str_replace(array('<', '>', '&'), array('\x3c', '\x3e', '\x26'), json_encode($var));
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.