| Package | system.web.helpers |
|---|---|
| Inheritance | class CJavaScript |
| Since | 1.0 |
| Version | $Id: CJavaScript.php 1783 2010-02-01 21:12:10Z qiang.xue $ |
| Method | Description | Defined By |
|---|---|---|
| encode() | Encodes a PHP variable into javascript representation. | CJavaScript |
| jsonDecode() | Decodes a JSON string. | CJavaScript |
| jsonEncode() | Returns the JSON representation of the PHP data. | CJavaScript |
| quote() | Quotes a javascript string. | CJavaScript |
|
public static string encode(mixed $value)
| ||
| $value | mixed | PHP variable to be encoded |
| {return} | string | the encoded string |
Encodes a PHP variable into javascript representation.
Example:
$options=array('key1'=>true,'key2'=>123,'key3'=>'value');
echo CJavaScript::encode($options);
// The following javascript code would be generated:
// {'key1':true,'key2':123,'key3':'value'}
|
public static mixed jsonDecode(string $data, boolean $useArray=true)
| ||
| $data | string | the data to be decoded |
| $useArray | boolean | whether to use associative array to represent object data |
| {return} | mixed | the decoded PHP data |
Decodes a JSON string.
|
public static string jsonEncode(mixed $data)
| ||
| $data | mixed | the data to be encoded |
| {return} | string | the JSON representation of the PHP data. |
Returns the JSON representation of the PHP data.
|
public static string quote(string $js, boolean $forUrl=false)
| ||
| $js | string | string to be quoted |
| $forUrl | boolean | whether this string is used as a URL |
| {return} | string | the quoted string |
Quotes a javascript string. After processing, the string can be safely enclosed within a pair of quotation marks and serve as a javascript string.
Be the first person to leave a comment
Please login to leave your comment.