PHP code example of ui-awesome / html-interop

1. Go to this page and download the library: Download ui-awesome/html-interop 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/ */

    

ui-awesome / html-interop example snippets




declare(strict_types=1);

namespace App;

use UIAwesome\Html\Interop\Block;

echo Block::DIV->value;
// 'div'

echo Block::ARTICLE->value;
// 'article'

echo Block::SECTION->value;
// 'section'



declare(strict_types=1);

namespace App;

use UIAwesome\Html\Interop\Inline;

echo Inline::SPAN->value;
// 'span'

echo Inline::STRONG->value;
// 'strong'

echo Inline::A->value;
// 'a'



declare(strict_types=1);

namespace App;

use UIAwesome\Html\Interop\Voids;

echo Voids::IMG->value;
// 'img'

echo Voids::INPUT->value;
// 'input'

echo Voids::BR->value;
// 'br'



declare(strict_types=1);

namespace App;

use UIAwesome\Html\Interop\{Lists, Root, Table};

// List elements
echo Lists::UL->value;
// 'ul'

echo Lists::OL->value;
// 'ol'

echo Lists::LI->value;
// 'li'

// Root elements
echo Root::HTML->value;
// 'html'

echo Root::HEAD->value;
// 'head'

echo Root::BODY->value;
// 'body'

// Table elements
echo Table::TABLE->value;
// 'table'

echo Table::THEAD->value;
// 'thead'

echo Table::TR->value;
// 'tr'

echo Table::TD->value;
// 'td'



declare(strict_types=1);

namespace App;

use BackedEnum;
use UIAwesome\Html\Interop\Block;

/**
 * Render HTML using any string-backed enum.
 */
function renderBlock(BackedEnum $tag, string $content): string
{
    return sprintf('<%s>%s</%s>', $tag->value, $content, $tag->value);
}

echo renderBlock(Block::DIV, 'Content');
// <div>Content</div>

echo renderBlock(Block::ARTICLE, 'Article content');
// <article>Article content</article>



declare(strict_types=1);

namespace App;

use UIAwesome\Html\Interop\Block;

// Filter heading elements
$headings = array_filter(
    Block::cases(),
    fn (Block $tag) => str_starts_with($tag->name, 'H'),
);

foreach ($headings as $heading) {
    echo $heading->value . PHP_EOL;
}
// h1
// h2
// h3
// h4
// h5
// h6

// Get all block tag names
$tagNames = array_map(fn (Block $tag) => $tag->value, Block::cases());