ropendev/phptojs 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

Quality Score Build Status SensioLabsInsight Total Downloads

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

GitHub 信息

  • Stars: 10
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-10-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固