PHP code example of cr0w / phml

1. Go to this page and download the library: Download cr0w/phml 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/ */

    

cr0w / phml example snippets




echo \phml\render(
    h('.card#main',
        h('h1', 'Hello, world!'),
        h('p', 'Built with phml.')
    )
);

h('div')                          // <div></div>
h('p.lead', 'Hello')              // <p class="lead">Hello</p>
h('section.full.dark#hero')       // <section class="full dark" id="hero"></section>
h('.card#main')                   // <div class="card" id="main"></div>  (tag defaults to div)

h('a', ['href' => '/about', 'class' => 'nav-link'], 'About')
// <a href="/about" class="nav-link">About</a>

$items = array_map(fn($i) => h('li', $i), ['One', 'Two', 'Three']);

h('ul', $items)
// <ul><li>One</li><li>Two</li><li>Three</li></ul>

h('div', $isAdmin ? h('button', 'Delete') : null)
// <div></div>

render(h('p', 'Hello'))           // <p>Hello</p>
render(h('br'))                   // <br>  (void tags have no closing tag)
render(null)                      // ''
render(false)                     // ''
render([h('li', 'A'), h('li', 'B')]) // <li>A</li><li>B</li>  (fragment)

c('btn', 'btn-lg')
// 'btn btn-lg'

c('btn', $isLarge && 'btn-lg')
// 'btn' or 'btn btn-lg'

c('btn', ['btn-primary' => $isPrimary, 'btn-disabled' => $isDisabled])
// 'btn btn-primary'

c(['px-4', ['text-lg' => $big]])
// 'px-4' or 'px-4 text-lg'

echo '<title>' . e($pageTitle) . '</title>';

render(h('div', raw('<strong>trusted</strong>')))
// <div><strong>trusted</strong></div>

h('input', ['type' => 'checkbox', 'checked' => true, 'disabled' => false])
// <input type="checkbox" checked>

h('div', ['style' => ['marginTop' => '1rem', 'color' => 'red']])
// <div style="margin-top: 1rem; color: red"></div>

h('div', ['data-' => ['userId' => 1, 'role' => 'admin']])
// <div data-user-id="1" data-role="admin"></div>

h('button', ['aria-' => ['label' => 'Close', 'expanded' => 'false']])
// <button aria-label="Close" aria-expanded="false"></button>

h('form', ['hx-' => ['post' => '/submit', 'swap' => 'outerHTML']])
// <form hx-post="/submit" hx-swap="outerHTML"></form>

h('div', ['x-' => ['data' => '{ open: false }', 'show' => 'open']])
// <div x-data="{ open: false }" x-show="open"></div>

h('div', ['hx-' => ['swapOob' => 'true']])
// <div hx-swap-oob="true"></div>