js-phpize / js-phpize
Convert js-like syntax to standalone PHP code.
Fund package maintenance!
kylekatarnls
Open Collective
Tidelift
Installs: 323 291
Dependents: 3
Suggesters: 0
Security: 0
Stars: 21
Watchers: 3
Forks: 3
Open Issues: 0
Requires
- php: >=7.0
- ext-mbstring: *
Requires (Dev)
- phpunit/phpunit: ^6.5.14 || ^7.5.20 || ^8.5.31 || ^9.5.27
- dev-master
- 2.9.1
- 2.9.0
- 2.8.5
- 2.8.4
- 2.8.3
- 2.8.2
- 2.8.1
- 2.8.0
- 2.7.1
- 2.7.0
- 2.6.0
- 2.5.0
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.0
- 1.14.0
- 1.13.0
- 1.12.2
- 1.12.1
- 1.12.0
- 1.11.2
- 1.11.1
- 1.11.0
- 1.10.2
- 1.10.1
- 1.10.0
- 1.9.1
- 1.9.0
- 1.8.1
- 1.8.0
- 1.7.8
- 1.7.7
- 1.7.6
- 1.7.5
- 1.7.4
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.1
- 1.0.0
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.11
- 0.1.10
- 0.1.9
- 0.1.8
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-feature/let
This package is auto-updated.
Last update: 2024-12-29 12:11:47 UTC
README
Convert js-like syntax to standalone PHP code.
Install
In the root directory of your project, open a terminal and enter:
composer require js-phpize/js-phpize
Usage
Use compile to get PHP equivalent code to JavaScript input:
use JsPhpize\JsPhpize; $jsPhpize = new JsPhpize(); echo $jsPhpize->compile('foo = { bar: { "baz": "hello" } }');
This code will output the following PHP code:
$foo = array( "bar" => array( "baz" => "hello" ) );
Or use render to execute it directly:
use JsPhpize\JsPhpize; $jsPhpize = new JsPhpize(); $code = ' // Create an object foo = { bar: { "baz": "hello" } }; key = 'bar'; // instanciate a string return foo[key].baz; '; $value = $jsPhpize->render($code); echo $value;
This will display hello
.
This library intend to is intended to allow js-like in PHP contexts (such as in template engines).
See the Phug documentation to see an implementation example as Pug expressions PHP converter.
And also check examples to see more examples (.js files are input examples js-phpize can handle and either .return show you what the engine will return for this code, or .php show you how it's compiled into PHP).