yii1-javascript-encode.php
Table of Contents
Classes
- Yii_CJavaScriptExpression
- CJavaScriptExpression represents a JavaScript expression that does not need escaping.
Functions
- php_to_js() : string
- Encodes a PHP variable into javascript representation.
- yii_quote() : mixed
Functions
php_to_js()
Encodes a PHP variable into javascript representation.
php_to_js(mixed $value[, bool $safe = false ]) : string
Example:
$options=array('key1'=>true,'key2'=>123,'key3'=>'value'); echo php_to_js($options); // The following javascript code would be generated: // {'key1':true,'key2':123,'key3':'value'}
For highly complex data structures use and to serialize and unserialize.
If you are encoding user input, make sure $safe is set to true.
Parameters
- $value : mixed
-
PHP variable to be encoded
- $safe : bool = false
-
If true, 'js:' will not be allowed. In case of wrapping code with JavaScript expression will stay as is no matter what value this parameter is set to. Default is false. This parameter is available since 1.1.11.
Return values
string —the encoded string
yii_quote()
yii_quote(mixed $js[, mixed $forUrl = false ]) : mixed
Parameters
- $js : mixed
- $forUrl : mixed = false