Source
? '<script type="text/javascript">'."\n".'jQuery(document).ready(function() { '.$script.' });'."\n".'</script>'
<?php
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/**
* Convert PHP variable to string version of JavaScript style
*
* @deprecated Use json_encode() instead.
*
* @param mixed $value
* @param bool $as_object return string containing javascript object
* @param bool $addQuotes whether quotes should be added at the beginning and at the end of string
*
* @return string
*/
function zbx_jsvalue($value, $as_object = false, $addQuotes = true) {
if (!is_array($value)) {
if (is_object($value)) {
return unpack_object($value);
}
elseif (is_string($value)) {
$escaped = str_replace("\r", '', $value); // removing caret returns
$escaped = str_replace("\\", "\\\\", $escaped); // escaping slashes: \ => \\
$escaped = str_replace('"', '\"', $escaped); // escaping quotes: " => \"
$escaped = str_replace("\n", '\n', $escaped); // changing LF to '\n' string
$escaped = str_replace('\'', '\\\'', $escaped); // escaping single quotes: ' => \'
$escaped = str_replace('/', '\/', $escaped); // escaping forward slash: / => \/
if ($addQuotes) {
$escaped = "'".$escaped."'";
}
return $escaped;
}
elseif (is_null($value)) {
return 'null';
}
elseif (is_bool($value)) {
return ($value) ? 'true' : 'false';
}
else {
return strval($value);
}
}
elseif (count($value) == 0) {
return $as_object ? '{}' : '[]';
}
$is_object = $as_object;
foreach ($value as $key => &$v) {
if (is_string($key)) {
$is_object = true;