drupal_to_js

Definition

drupal_to_js($var)
drupal/includes/common.inc, line 2768

Description

Converts a PHP variable into its Javascript equivalent.

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

Related topics

Namesort iconDescription
Input validationFunctions to validate user input.

Code

function drupal_to_js($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));
}