Warning
Experimental project – give it a try
Source input:
<>
<h1 className="title">Hello, {$name ?? ucfirst($type)}!</h1>
<p>
Welcome to the world of PHPX, where you can write PHP code in a JSX-like syntax.
<img src="about:blank" alt="Happy coding!" /> forever!
</p>
</>
Compiled output:
[
['$', 'h1', ['className'=>"title"], ['Hello, ', ($name ?? ucfirst($type)), '!']],
['$', 'p', null, [
'Welcome to the world of PHPX, where you can write PHP code in a JSX-like syntax.',
['$', 'img', ['src'=>"about:blank", 'alt'=>"Happy coding!"]], ' forever!',
]],
]
Important
This project is not yet published to Packagist. You need to add the repository manually or clone the repository as a submodule.
$ git submodule add [email protected]:attitude/phpx.git path/to/phpx
Update composer.json
of your project:
{
...,
"repositories": [
{
"type": "vcs",
"url": "https://github.com/attitude/phpx"
}
],
"require": {
"attitude/phpx": "dev-main"
}
}
$ composer install
<?php
require_once 'path/to/phpx/src/Compiler.php';
$phpx = new \Attitude\PHPX\Compiler();
$phpx->compile(<<<'PHPX'
<>
<h1 className="title">Hello, {$name ?? ucfirst($type)}!</h1>
<p>
Welcome to the world of PHPX, where you can write PHP code in a JSX-like syntax.
<img src="about:blank" alt="Happy coding!" /> forever!
</p>
</>
PHPX);
Enjoy!
Created by martin_adamko