PHPackages                             ropendev/phptojs - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ropendev/phptojs

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ropendev/phptojs
================

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

1.1.1(11y ago)105.8k↓11.1%2[1 issues](https://github.com/RobinDev/PHPToJS/issues)1MITPHPPHP &gt;=5.3.0

Since Nov 3Pushed 11y ago1 watchersCompare

[ Source](https://github.com/RobinDev/PHPToJS)[ Packagist](https://packagist.org/packages/ropendev/phptojs)[ Docs](http://www.robin-d.fr/)[ RSS](/packages/ropendev-phptojs/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (1)

Convert PHP Variable to Javascript Variable
===========================================

[](#convert-php-variable-to-javascript-variable)

[![Quality Score](https://camo.githubusercontent.com/cdadf1580e128fe5262474c9ccc100daaf2e75d6c81a6a941e198c2accf38785/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f526f62696e4465762f504850546f4a532e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/RobinDev/PHPToJS)[![Build Status](https://camo.githubusercontent.com/94f74656a0f5b2635e1a7cee09e62ec87a227315701d45f6448eaaf0fcc3cac2/68747470733a2f2f7472617669732d63692e6f72672f526f62696e4465762f504850546f4a532e737667)](https://travis-ci.org/RobinDev/PHPToJS)[![SensioLabsInsight](https://camo.githubusercontent.com/a74a06728f62dc7a341c52e9fce75454132430118570b4eee9b51629549dfbb1/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f32663465623566322d326334392d346463652d393066352d3464313961386437633833622f6d696e692e706e67)](https://insight.sensiolabs.com/projects/2f4eb5f2-2c49-4dce-90f5-4d19a8d7c83b)[![Total Downloads](https://camo.githubusercontent.com/17070b1a8265fdc2a1fd6341d6c903e70e1f9811cfd6458d58abc5d5985a7d16/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f70656e6465762f706870746f6a732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ropendev/phptojs)

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
------------

[](#installation)

Composer Friendly (via [packagist](https://packagist.org/packages/ropendev/phptojs)):

```
composer require ropendev/phptojs
```

Usage
-----

[](#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
-------

[](#licence)

MIT

Contributors
------------

[](#contributors)

- [Robin](http://www.robin-d.fr/)

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~32 days

Total

3

Last Release

4151d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/afce4cf517928a50560237f1410d5957271fd808671b2216687ecf1422adaee0?d=identicon)[Robin D.](/maintainers/Robin%20D.)

---

Tags

javascriptphp to jsjson\_encode

### Embed Badge

![Health badge](/badges/ropendev-phptojs/health.svg)

```
[![Health](https://phpackages.com/badges/ropendev-phptojs/health.svg)](https://phpackages.com/packages/ropendev-phptojs)
```

###  Alternatives

[tightenco/ziggy

Use your Laravel named routes in JavaScript.

4.3k41.6M267](/packages/tightenco-ziggy)[matthiasmullie/minify

CSS &amp; JavaScript minifier, in PHP. Removes whitespace, strips comments, combines files (incl. @import statements and small assets in CSS files), and optimizes/shortens a few common programming patterns.

2.0k30.5M336](/packages/matthiasmullie-minify)[laracasts/utilities

Transform your PHP to JavaScript

2.2k10.0M39](/packages/laracasts-utilities)[tedivm/jshrink

Javascript Minifier built in PHP

76037.7M139](/packages/tedivm-jshrink)[symfony/ux-turbo

Hotwire Turbo integration for Symfony

3906.8M47](/packages/symfony-ux-turbo)[tecnickcom/tc-lib-color

PHP library to manipulate various color representations

247.2M9](/packages/tecnickcom-tc-lib-color)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
