getJsValue() public static method

Formats an javascript assignment with proper escaping of a value and support for assigning array of strings.
public static getJsValue ( string $key, mixed $value, boolean $escape = true ) : string
$key string Name of value to set
$value mixed Value to set, can be either string or array of strings
$escape boolean Whether to escape value or keep it as it is (for inclusion of js code)
return string Javascript code.
示例#1
0
 /**
  * Test for Sanitize::getJsValue
  *
  * @param string $key      Key
  * @param string $value    Value
  * @param string $expected Expected output
  *
  * @dataProvider variables
  *
  * @return void
  */
 public function testGetJsValue($key, $value, $expected)
 {
     $this->assertEquals($expected, Sanitize::getJsValue($key, $value));
     $this->assertEquals('foo = 100', Sanitize::getJsValue('foo', '100', false));
     $array = array('1', '2', '3');
     $this->assertEquals("foo = [\"1\",\"2\",\"3\",];\n", Sanitize::getJsValue('foo', $array));
     $this->assertEquals("foo = \"bar\\\"baz\";\n", Sanitize::getJsValue('foo', 'bar"baz'));
 }
示例#2
0
/**
 * Adds JS code snippet for variable assignment
 * to be displayed by the PMA\libraries\Response class.
 *
 * @param string $key    Name of value to set
 * @param mixed  $value  Value to set, can be either string or array of strings
 * @param bool   $escape Whether to escape value or keep it as it is
 *                       (for inclusion of js code)
 *
 * @return void
 */
function PMA_addJSVar($key, $value, $escape = true)
{
    PMA_addJSCode(Sanitize::getJsValue($key, $value, $escape));
}
示例#3
0
 /**
  * Prints an javascript assignment with proper escaping of a value
  * and support for assigning array of strings.
  *
  * @param string $key   Name of value to set
  * @param mixed  $value Value to set, can be either string or array of strings
  *
  * @return void
  */
 public static function printJsValue($key, $value)
 {
     echo Sanitize::getJsValue($key, $value);
 }