1. Go to this page and download the library: Download maxpertici/markup 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/ */
use MaxPertici\Markup\MarkupFlow;
$nav = new Markup(
wrapper: '<ul>%children%</ul>',
childrenWrapper: '<li>%child%</li>',
children: [
'Home',
'About',
new MarkupFlow([
'Products',
new Markup(
wrapper: '<ul>%children%</ul>',
children: [
'<li>Electronics</li>',
'<li>Clothing</li>',
'<li>Books</li>',
]
),
]),
'Contact',
]
);
echo $nav->render();
use MaxPertici\Markup\Markup;
// Fetch and parse HTML
$html = file_get_contents('https://example.com/blog');
$page = Markup::fromHtml(html: $html);
// Find articles and process with collection methods
$articles = $page->find()->tag('article')->get();
$articles->each(function($article) {
// Get title and excerpt
$title = $article->find()->tag('h2')->first();
$excerpt = $article->find()->tag('p')->first();
if ($title) {
echo "Title: " . $title->text() . "\n";
}
if ($excerpt) {
echo "Excerpt: " . $excerpt->text() . "\n";
}
echo "---\n";
});
// Get only featured articles
$featured = $page->find()->tag('article')->get()
->filter(fn($article) => $article->hasClass('featured'));
// Extract all titles
$titles = $page->find()->tag('article')->get()
->map(fn($article) => $article->find()->tag('h2')->first())
->filter(fn($title) => $title !== null)
->map(fn($title) => $title->text());
// Take first 5 articles and enhance them
$page->find()->tag('article')->get()
->take(5)
->each(fn($article) => $article->addClass('featured-item'));
echo $page->render();
// Create elements with Markup::make()
$div = Markup::make(
tag: 'div',
classes: ['container'],
attributes: ['id' => 'main']
);
$div->append('Content here');
// Or use MarkupFactory directly
$div = MarkupFactory::create(
tag: 'div',
classes: ['container'],
attributes: ['id' => 'main']
);
// Parse HTML with Markup::fromHtml()
$markup = Markup::fromHtml(html: '<div class="box">Content</div>');
$markup->addClass('shadow');
// Or use MarkupFactory directly
$markup = MarkupFactory::fromHtml(html: '<div class="box">Content</div>');
// Use predefined elements with enums
use MaxPertici\Markup\Elements\HtmlTag;
$button = MarkupFactory::fromElement(
element: HtmlTag::BUTTON,
children: ['Click me'],
classes: ['btn', 'btn-primary']
);
$page->find()->css('.section')->get(); // by class
$page->find()->css('div')->get(); // by tag
$page->find()->css('#hero')->first(); // by ID
$page->find()->css('[role="main"]')->get(); // by attribute
$page->find()->css('nav li.active')->get(); // combined
$page->find()->css('.header > nav')->get(); // direct child
$page->find()->css('nav:has(li.active)')->get(); // has pseudo-class
// Filter elements
$featured = $page->find()->tag('article')->get()
->filter(fn($article) => $article->hasClass('featured'));
// Map and transform
$titles = $page->find()->tag('h2')->get()
->map(fn($title) => $title->text());
// Take subset
$first5 = $page->find()->tag('p')->get()->take(5);
// Iterate with each
$page->find()->css('.card')->get()
->each(fn($card) => $card->addClass('enhanced'));
// Chain methods
$page->find()->tag('article')->get()
->filter(fn($article) => $article->hasClass('published'))
->take(10)
->each(fn($article) => $article->addClass('featured'));
use MaxPertici\Markup\Contracts\MarkupElementInterface;
enum BootstrapComponent implements MarkupElementInterface {
case CARD;
case BUTTON_PRIMARY;
case ALERT_SUCCESS;
// ... implement
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.