wert1209yt / htmlman
Object-oriented HTML generator and declarative UI builder for PHP without extra files.
v1.0.1
2026-09-06 13:24 UTC
Requires
- php: >=8.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A lightweight PHP framework for efficient HTML generation.
Why us
- Maximum OOP
- Create HTML elements directly in PHP using the corresponding classes, for example:
new P('Example!'),new Div([ new P('Example)]) - Register your elements to simplify things: you can register a class associated with a
div—complete with HTML classes, styles, and even a nested structure — and the engine will automatically locate the innermost element and inject the content there! (And WebComponents support) - Formatting your HTML structure via
->format()adds indentation to the element class and nested elements (by default, minified HTML without indentation is output). - Adding classes, IDs, and styles to elements is supported via
->class('example example-has-padding'),->id('123'), and->style('display: none;'). - Support for all HTML5 elements, except obsolete ones, though you can register any obsolete element.
- Auto-screening of content (can be disabled by
->raw())
How to get started
First, you need to install it via Composer:
composer require wert1209yt/htmlman
Usage in your project:
<?php require_once 'vendor/autoload.php'; HtmlMan::init(); // Init will add all base HTML5 elements classes ?>
Register your custom elements classes
HtmlMan::register([ 'name' => 'Card', 'tag' => 'div', // Or any html tag (WebComponents support) 'class' => 'card', 'id' => '123', 'style' => [ 'background-color' => '#ffffff', 'border' => '1px solid #ddd' ], // Or string 'background-color: #ffffff; border: 1px solid #ddd' // Element structure 'structure' => new Main([ (new Div([ new P() // Will put content there ]))->class('card-body') ]) ]);
Minimal (example):
HtmlMan::register([ 'name' => 'YourElement', 'tag' => 'div' ])
Base use
$div = new Div([ new P('Example)]) echo $div->format();
Add class, id or style:
$div = (new Div([ new P('Example)])) ->class('example') ->id('123') ->style('display: none');
You can add indents using formatting:
$html = (new Div([ new P('Example)])) ->format();
If you want link:
echo (new A('link')) ->href('https://github.com') ->target('_blank') ->class('link-style');
