ropendev/phptojs
Composer 安装命令:
composer require ropendev/phptojs
包简介
PHPToJS's class convert php variable's content to js variable's content preserving javascript expression (like function)
README 文档
README
PHPToJS's class convert php variable's content to js variable's content preserving javascript expression (like function).
This class is perfect if you were limited by php function json_encode, json's validity and/or JSON.parse when you have a javascript function.
To Know : A php array with keys can't be a javascript array... so it will become a javascript object.
Installation
Composer Friendly (via packagist):
composer require ropendev/phptojs
Usage
You just need to call static function \rOpenDev\PHPToJS::render($mixed). Example :
use \rOpenDev\PHPToJS; $options = (object) array( 'title' => (object) array( 'label' => 'PHP To JS charts', 'class' => 'titlechart', 'formatter' => 'function(s) { return s.replace("-", "/"); }', ), 'data' => array(2014,2013,2012,2011) ); echo PHPToJS::render($options);
Will render :
{title:{label:"PHP To JS charts",class:"titlechart",formatter:function(s) { return s.replace("-", "/"); }},data:[2014,2013,2012,2011]}
You can use renderReadable function which would render :
{
title: {
label: "PHP To JS charts",
class: "titlechart",
formatter: function(s) { return s.replace("-", "/"); }
},
data: [
2014,
2013,
2012,
2011
]
}
This function is available only in v1.0.0 !
Licence
MIT
Contributors
统计信息
- 总下载量: 6.27k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-10-14