2017 © Pedro Peláez
 

library phptojs

PHPToJS's class convert php variable's content to js variable's content preserving javascript expression (like function)

image

ropendev/phptojs

PHPToJS's class convert php variable's content to js variable's content preserving javascript expression (like function)

  • Wednesday, January 7, 2015
  • by RobinD
  • Repository
  • 1 Watchers
  • 5 Stars
  • 3,260 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 4 Versions
  • 1 % Grown

The README.md

Convert PHP Variable to Javascript Variable

Quality Score Build Status SensioLabsInsight Total Downloads, (*1)

PHPToJS's class convert php variable's content to js variable's content preserving javascript expression (like function)., (*2)

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., (*3)

To Know : A php array with keys can't be a javascript array... so it will become a javascript object., (*4)

Installation

Composer Friendly (via packagist):, (*5)

composer require ropendev/phptojs

Usage

You just need to call static function \rOpenDev\PHPToJS::render($mixed). Example :, (*6)

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 :, (*7)

{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 :, (*8)

{
    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 !, (*9)

Licence

MIT, (*10)

Contributors

The Versions

07/01 2015

dev-master

9999999-dev http://www.robin-d.fr/

PHPToJS's class convert php variable's content to js variable's content preserving javascript expression (like function)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

javascript json_encode php to js

06/01 2015

1.1.1

1.1.1.0 http://www.robin-d.fr/

PHPToJS's class convert php variable's content to js variable's content preserving javascript expression (like function)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

javascript json_encode php to js

02/01 2015

1.1.0

1.1.0.0 http://www.robin-d.fr/

PHPToJS's class convert php variable's content to js variable's content preserving javascript expression (like function)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

javascript json_encode php to js

03/11 2014

1.0.0

1.0.0.0 http://www.robin-d.fr/

PHPToJS's class convert php variable's content to js variable's content preserving javascript expression (like function)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Avatar robin

javascript json_encode php to js