Skip to content

Commit 3a7a909

Browse files
author
Pranjal Pandey
authored
Update README.md
1 parent e4dd3a7 commit 3a7a909

File tree

1 file changed

+76
-2
lines changed

1 file changed

+76
-2
lines changed

README.md

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,76 @@
1-
# php2js
2-
convert php code to javascript code that run on browser
1+
# PIQON PHP2JS
2+
Convert php code to javascript code that can run on browser
3+
4+
### Installation
5+
package can be installed via composer<br>
6+
```
7+
composer require piqon/php2js
8+
```
9+
10+
### Usage
11+
If You want to create a copiled javascript file , you can run the following code: <br>
12+
13+
```php
14+
<?php
15+
include __DIR__ . '/vendor/autoload.php';
16+
17+
/*
18+
* Replace test.php with path of your input php file
19+
* Replace test.js with path for your js file output
20+
*/
21+
22+
\PHP2JS\PHP2JS::compileFile(__DIR__.'/test.php',__DIR__.'/test.js');
23+
```
24+
25+
If you just want to convert a small block of code , you can run the following code:
26+
27+
```php
28+
<?php
29+
include __DIR__ . '/vendor/autoload.php';
30+
31+
$code = "
32+
$name='1';
33+
echo 'hi';
34+
"
35+
36+
\PHP2JS\PHP2JS::compile($code);
37+
```
38+
39+
### Demo
40+
41+
Input code :
42+
43+
```php
44+
<?php
45+
$name = 'Pranjal';
46+
$cars = ['BMW','Audi'];
47+
$cars->push('Ferrari');
48+
echo $name;
49+
echo $cars;
50+
51+
function click(){
52+
echo 'button clicked!';
53+
}
54+
```
55+
56+
Output code:
57+
```javascript
58+
59+
let name = 'Pranjal';
60+
let cars = ['BMW', 'Audi'];
61+
cars.push('Ferrari');
62+
console.log( name);
63+
console.log( cars);
64+
65+
function click()
66+
{
67+
console.log( 'button clicked!');
68+
}
69+
70+
```
71+
72+
73+
### Note
74+
This was designed to convert php scripts to javascript code , this might not work with full blown php classes !
75+
You can call javascript functions like console.log etc right from your php code and it will work as expected in the browser.
76+
This compiler does not support magic variables and magic functions of PHP.

0 commit comments

Comments
 (0)