drupal_to_js($var)
drupal/includes/common.inc, line 2768
Converts a PHP variable into its Javascript equivalent.
We use HTML-safe strings, i.e. with <, > and & escaped.
| Name | Description |
|---|---|
| Input validation | Functions to validate user input. |
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));
}