PHP code example of buttress / phpx-compile

1. Go to this page and download the library: Download buttress/phpx-compile library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

buttress / phpx-compile example snippets




$x = new Buttress\Phpx\Phpx();
$github = 'https://github.com/buttress/phpx';

return $x->render(
    $x->div(class: 'content', c: [
        $x->h1(id: 'title', c: 'Hello World!'),
        $x->p(c: [
            'Brought to you by ',
            $x->a(href: $github, c: 'PHPX')
        ]),
    ])
);


$x = new Buttress\Phpx\Phpx();
$github = 'https://github.com/buttress/phpx';
return '<div class="content"><h1 id="title">Hello World!</h1>'.'<p>Brought to you by '.'<a href="'.htmlspecialchars($github, 50).'">PHPX</a>'.'</p>'.'</div>';

/** Basic Usage */

$parser = (new \PhpParser\ParserFactory())->createForHostVersion();
$compiler = new \Buttress\Compiler($parser);

$phpxVariable = 'x'; // The variable name I use in my phpx files.
$input = file_get_contents('/my_file_that_uses_phpx');
$php = $compiler->compile($input, $phpxVariable);