PHPackages                             one234ru/html-tag-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. one234ru/html-tag-generator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

one234ru/html-tag-generator
===========================

 PHP tool for generating code of HTML tags.

v1.0.3(2y ago)0271GPL-3.0-or-laterPHPPHP &gt;=7.1

Since May 19Pushed 2y ago1 watchersCompare

[ Source](https://github.com/1234ru/html-tag-generator)[ Packagist](https://packagist.org/packages/one234ru/html-tag-generator)[ RSS](/packages/one234ru-html-tag-generator/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependenciesVersions (4)Used By (1)

**[ПО-РУССКИ](README-RU.md)**

HTML tags source code generation based on configuration array
=============================================================

[](#html-tags-source-code-generation-based-on-configuration-array)

Installation
------------

[](#installation)

### Composer

[](#composer)

```
composer require one234ru/html-tag-generator:dev-main
```

### Manual

[](#manual)

The library doesn't have any dependencies. Only [HTMLtagGenerator.php](https://raw.githubusercontent.com/1234ru/html-tag-generator/main/HTMLtagGenerator.php) file is required for work.

```
require_once 'HTMLtagGenerator.php';
```

Usage
-----

[](#usage)

Create the object passing configuration array to the constructor. Then get an HTML code treating the object as a string:

```
$config = [ ... ];
$html_tag = new \One234ru\HTMLtagGenerator($config);
echo $html_tag;
```

Description of configuration fields
-----------------------------------

[](#description-of-configuration-fields)

### `tag` and `text`

[](#tag-and-text)

`tag` is the tag's name, `div` by default.

`text` will be inserted right after opening tag.

**Examples**

Configuration:

```
[
    'text' => 'Here is some text'
]
```

Result:

```
Here is some text
```

Configuration:

```
[
    'tag' => 'span',
    'text' => 'Here is some text'
]
```

Result:

```
Here is some text
```

Tags with no closing part (like `input`) will be detected automatically and processed appropriately.

### `attr`

[](#attr)

`attr` is a list of attributes in a form of key-value pairs.

All the values are encoded using [htmlspecialchars()](https://www.php.net/htmlspecialchars).

If the value is an array, it will be turned into JSON.

```
[
    'text' => 'Here is some text',
    'attr' => [
        'id' => 'main',
        'class' => 'someclass',
        'style' => 'font-weight: bold',
        'data-something' => [ 'x' => 1, 'y' => 2 ]
    ]
]
```

Result (formatted for readability):

```

    Here is some text

```

Some attributes, like `checked`, are treated in a special way: if the value converts to boolean `true`, only their names go to final HTML, otherwise nothing goes anywhere:

```
[
    'tag' => 'input',
    'attr' => [
        'type' => 'checkbox',
        'checked' => true
    ]
]
```

```

```

```
[
    'tag' => 'input',
    'attr' => [
        'type' => 'checkbox',
        'checked' => false
    ]
]
```

```

```

This is done for disambiguation of unobvious feature deriving from HTML standard, which leads to `` or `` eventually working the same way as ``, i.e. the actual value of the attribute not affecting anything even if it is `false` or something like that, and the only way to discard the attribute is to exclude it completely.

### `children`

[](#children)

The `children` field serves for listing of children elements in the form of similar configurations.

Their source code will be inserted after `text`:

```
[
    'text' => 'Did you like it?',
    'children' => [
        [
            'tag' => 'input',
            'attr' => [
                'type' => 'submit',
                'value' => 'Yes!', // Да!
            ],
        ],
        [
            'tag' => 'input',
            'attr' => [
                'type' => 'reset',
                'value' => 'No', // Нет
            ]
        ],
        [
            'tag' => 'button',
            'text' => "I don't know", // Не знаю
        ]
    ]
]
```

```

    Did you like it?

    I don't know

```

You can pass HTML as a string directly instead of an array:

```
[
    'tag' => 'ul',
    'children' => [
        'One',
        'Two',
        'Three',
    ]
]
```

```

    One
    Two
    Three

```

It is not necessary to wrap the contents into tags:

```
[
    'children' => [
        'This is the text at the beginning. ',
        'This is a bold text. ',
        'This is the text at the end.',
    ]
]
```

```
This is the text at the beginning. This is a bold text. This is the text at the end.
```

Actually, the following two configurations yield the same result:

```
[
    'text' => 'Here is some text'
]
```

```
[
    'children' => [
        'Here is some text'
    ]
]
```

```
Here is some text
```

If a string is passed as a configuration, it will be used as final HTML; this fact is utilized when `children` are passed as strings. The following two configurations are equivalent:

```
[
    'text' => 'Here is some text'
]
```

```
'Here is some text'
```

Result:

```
Here is some text
```

Inheritance: normalizing configuration (`normalizeConfig()`)
------------------------------------------------------------

[](#inheritance-normalizing-configuration-normalizeconfig)

When extending the class, you may define protected `normalizeConfig()` method, which allows using configurations of non-standard structure.

Let's say, we often use `class` attribute and would like to define it at the highest level of array, not inside the `attr`. In this case we need to create a child class:

```
class Test extends \One234ru\HTMLtagGenerator {
    protected function normalizeConfig($config)
    {
        if (isset($config['class'])) {
            $config['attr']['class'] = $config['class'];
            unset($config['class']);
        }
        return $config;
    }
}

echo new Test([
    'class' => 'something',
]);

// Same thing using the basic class:
echo new \One234ru\HTMLtagGenerator([
    'attr' => [
        'class' => 'something'
    ]
]);
```

Result:

```

```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

775d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bd77b21d6b666e1667312dee933705103583e22280a835961017916531661ffc?d=identicon)[one234ru](/maintainers/one234ru)

---

Top Contributors

[![1234ru](https://avatars.githubusercontent.com/u/840808?v=4)](https://github.com/1234ru "1234ru (9 commits)")

### Embed Badge

![Health badge](/badges/one234ru-html-tag-generator/health.svg)

```
[![Health](https://phpackages.com/badges/one234ru-html-tag-generator/health.svg)](https://phpackages.com/packages/one234ru-html-tag-generator)
```

###  Alternatives

[underwear/laravel-vue-good-table

Vue-good-table wrapper for Laravel. Server side tables without pain.

4016.7k](/packages/underwear-laravel-vue-good-table)[wildbit/craft3-donottrack

Craft 3 plugin for respecting Do Not Track headers sent by browsers.

144.3k](/packages/wildbit-craft3-donottrack)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
