https://github.com/scrawler-labs/php2js
Convert php code to javascript code that run on browser [Experimental]
https://github.com/scrawler-labs/php2js
compiler javascript php php2js
Last synced: about 2 months ago
JSON representation
Convert php code to javascript code that run on browser [Experimental]
- Host: GitHub
- URL: https://github.com/scrawler-labs/php2js
- Owner: scrawler-labs
- Created: 2021-05-23T18:48:21.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2023-12-15T02:54:30.000Z (over 2 years ago)
- Last Synced: 2025-11-02T22:17:36.327Z (8 months ago)
- Topics: compiler, javascript, php, php2js
- Language: PHP
- Homepage:
- Size: 22.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PHP2JS
Convert php code to javascript code that can run on browser
### Installation
package can be installed via composer
```
composer require piqon/php2js
```
### Usage
If You want to create a copiled javascript file , you can run the following code:
```php
push('Ferrari');
echo $name;
echo $cars;
function click(){
echo 'button clicked!';
}
```
Output code:
```javascript
let name = 'Pranjal';
let cars = ['BMW', 'Audi'];
cars.push('Ferrari');
console.log( name);
console.log( cars);
function click()
{
console.log( 'button clicked!');
}
```
### Note
This was designed to convert php scripts to javascript code , this might not work with full blown php classes !
You can call javascript functions like console.log etc right from your php code and it will work as expected in the browser.
This compiler does not support magic variables and magic functions of PHP.
### Changelog
#### v0.3.0
- Added support for import : `include 'test'` now converts to `import test from './test.js'`
You can also use import_from() php function to define path of module.
Example:
```php
import_from('test','./component/test.js');
```
will compile to
```js
import test from './component/test.js';
```
- Added support for async function declaration via comment:
```php
// @async
function abc(){
return 'hi';
}
```
will compile to
```js
async function abc(){
return 'hi';
}
```