Painless html generation.
You can install the package via composer.
composer require authanram/html
Here's an example of how it can be used in a very basic way:
use Authanram\Html\Renderer;
$qux = [
'tag' => 'a',
'attributes' => [
'href' => 'https://github.com/authanram',
'class' => 'text-blue-600',
'data-anchor' => true,
],
'contents' => [
'authanram at github.com'
],
];
Renderer::renderFromArray($qux);
Renderer::renderFromArray($qux);
will return the following string
:
<a href="https://github.com/authanram" class="text-blue-600" data-anchor>
authanram at github.com
</a>
use Authanram\Html\Renderer;
$qux = [
'tag' => 'p',
'contents' => [
[
'tag' => 'a',
'attributes' => [
'class' => 'text-blue-600',
'href' => 'https://github.com/authanram',
],
'contents' => [
[
'tag' => 'span',
'class' => 'semibold',
'contents' => [
['authanram at github.com'],
]
],
],
],
],
];
Renderer::renderFromArray($qux);
Renderer::renderFromArray($qux);
will return the following string
:
<p>
<a class="text-blue-600" href="https://github.com/authanram">
<span class="semibold">
authanram at github.com
</span>
</a>
</p>
As you can see here,
we can achieve the same result using the static method Authanram\Html\Element::make()
:
use Authanram\Html\Element;
Element::make(
'a',
[
'href' => 'https://gitub.com',
'class' => 'text-blue-600',
],
['authanram at github.com'],
)->render();
...
use Authanram\Html\Element;
Element::parse('a.text-blue-600[href=https://gitub.com]')
->render();
The MIT License (MIT). Please see License File for more information.