{"id":20684559,"url":"https://github.com/php-forge/html-helper","last_synced_at":"2026-04-18T18:35:57.650Z","repository":{"id":224957785,"uuid":"764671311","full_name":"php-forge/html-helper","owner":"php-forge","description":"Awesome HTML Helper Code Generator for PHP.","archived":false,"fork":false,"pushed_at":"2024-03-03T11:28:26.000Z","size":45,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-16T05:34:24.995Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/php-forge.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-28T14:01:40.000Z","updated_at":"2024-02-28T14:55:40.000Z","dependencies_parsed_at":"2025-01-17T16:13:19.479Z","dependency_job_id":"b1bd4161-6682-42a2-8368-657dafd9f6f1","html_url":"https://github.com/php-forge/html-helper","commit_stats":null,"previous_names":["php-forge/html-helper"],"tags_count":4,"template":false,"template_full_name":"yii-tools/template","purl":"pkg:github/php-forge/html-helper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-forge%2Fhtml-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-forge%2Fhtml-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-forge%2Fhtml-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-forge%2Fhtml-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-forge","download_url":"https://codeload.github.com/php-forge/html-helper/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-forge%2Fhtml-helper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31980346,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T17:30:12.329Z","status":"ssl_error","status_checked_at":"2026-04-18T17:29:59.069Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T22:22:52.325Z","updated_at":"2026-04-18T18:35:57.630Z","avatar_url":"https://github.com/php-forge.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/php-forge/html-helper\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://avatars.githubusercontent.com/u/121752654?s=200\u0026v=4\" height=\"100px\"\u003e\n    \u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eAwesome HTML Helpers Code Generator for PHP.\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/php-forge/html-helper/actions/workflows/build.yml\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://github.com/php-forge/html-helper/actions/workflows/build.yml/badge.svg\" alt=\"PHPUnit\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/php-forge/html-helper\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://codecov.io/gh/php-forge/html-helper/branch/main/graph/badge.svg?token=MF0XUGVLYC\" alt=\"Codecov\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://dashboard.stryker-mutator.io/reports/github.com/php-forge/html-helper/main\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fphp-forge%2Fhtml-helper%2Fmain\" alt=\"Infection\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/php-forge/html-helper/actions/workflows/static.yml\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://github.com/php-forge/html-helper/actions/workflows/static.yml/badge.svg\" alt=\"Psalm\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://shepherd.dev/github/php-forge/html-helper\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://shepherd.dev/github/php-forge/html-helper/coverage.svg\" alt=\"Psalm Coverage\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.styleci.io/repos/764671311?branch=main\"\u003e\n        \u003cimg src=\"https://github.styleci.io/repos/764671311/shield?branch=main\" alt=\"Style ci\"\u003e\n    \u003c/a\u003e    \n\u003c/p\u003e\n\nHTML Helper is a PHP library that simplifies the creation of HTML elements. It provides a set of classes to generate\nHTML attributes, encode content, sanitize HTML content, and more.\n\n\n## Installation\n\nThe preferred way to install this extension is through [composer](https://getcomposer.org/download/).\n\nEither run\n\n```shell\ncomposer require --prefer-dist php-forge/html-helper:^0.1\n```\n\nor add\n\n```json\n\"php-forge/html-helper\": \"^0.1\"\n```\n\nto the require section of your `composer.json` file. \n\n## Usage\n\n### Add CSS classes\n\nThe `CssClasses::class` helper can be used to add CSS classes to an HTML element.\n\nThe method accepts three parameters:\n\n- `attributes:` (array): The HTML attributes of the element.\n- `classes:` (array|string): The CSS classes to add.\n- `overwrite:` (bool): Whether to overwrite the `class` attribute or not. For default, it is `false`.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse PHPForge\\Html\\Helper\\CssClasses;\n\nprivate array $attributes = [];\n\n$classes = CssClasses::add($this-\u003eattributes, ['btn', 'btn-primary', 'btn-lg']);\n```\n\nOverwriting the `class` attribute:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse PHPForge\\Html\\Helper\\CssClasses;\n\nprivate array $attributes = ['class' =\u003e 'btn'];\n\n$classes = CssClasses::add($this-\u003eattributes, ['btn-primary', 'btn-lg'], true);\n```\n\n### Convert regular expression to pattern\n\nThe `Utils::class` helper can be used to normalize a regular expression.\n\nThe method accepts one parameter:\n\n- `regexp:` (string): The pattern to normalize.\n- `delimiter:` (string): The delimiter to use. For default, it is `null`.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse PHPForge\\Html\\Helper\\Utils;\n\n$pattern = Utils::convertToPattern('/([a-z0-9-]+)/im'); // return: `([a-z0-9-]+)`\n```\n\n### Encode content\n\nThe `Encode::class` helper can be used to encode HTML content.\n\nThe method accepts tree parameters:\n\n- `content:` (string): The content to encode.\n- `doubleEncode:` (bool): Whether to double encode the content or not. For default, it is `true`.\n- `charset:` (string): The charset to use. For default, it is `UTF-8`.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse PHPForge\\Html\\Helper\\Encode;\n\n$content = Encode::html('\u003cscript\u003ealert(\"Hello, World!\")\u003c/script\u003e');\n```\n\n### Encode value\n\nThe `Encode::class` helper can be used to encode HTML value.\n\nThe method accepts tree parameters:\n\n- `value:` (string): The value to encode.\n- `doubleEncode:` (bool): Whether to double encode the value or not. For default, it is `true`.\n- `charset:` (string): The charset to use. For default, it is `UTF-8`.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse PHPForge\\Html\\Helper\\Encode;\n\n$value = Encode::value('\u003cscript\u003ealert(\"Hello, World!\")\u003c/script\u003e');\n```\n\n### Get short class name\n\nThe `Utils::class` helper can be used to get the short class name.\n\nThe method accepts one parameter:\n\n- `class:` (string): The class name to get the short name.\n- `suffix:` (string): Whether to append the `::class` suffix to the class name. \n  For default, it is `true`. If it is `false`, the method will return the short name without the `::class` suffix.\n- `lowercase:` (bool): Whether to convert the class name to lowercase or not. \n  For default, it is `false`.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse PHPForge\\Html\\Helper\\Utils;\n\n$shortName = Utils::getShortClassName('PHPForge\\Html\\Helper\\Utils'); // return: `Utils::class`\n```\n\n### Generate arrayable name\n\nThe `ArrayableName::class` helper can be used to generate an arrayable name.\n\nThe method accepts one parameter:\n\n- `name:` (string): The name to generate.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse PHPForge\\Html\\Helper\\Utils;\n\n$name = Utils::generateArrayableName('name');\n```\n\n### Generate input id\n\nThe `Utils::class` helper can be used to generate an input id.\n\nThe method accepts tree parameters:\n\n- `fieldModel:` (string): The name of the field model.\n- `property:` (string): The name of the property.\n- `charset:` (string): The charset to use. For default, it is `UTF-8`.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse PHPForge\\Html\\Helper\\Utils;\n\n$id = Utils::generateInputId('user', 'name');\n```\n\n### Generate input name\n\nThe `Utils::class` helper can be used to generate an input name.\n\nThe method accepts tree parameters:\n\n- `fieldModel:` (string): The name of the field model.\n- `property:` (string): The name of the property.\n- `arrayable:` (bool): Whether the name is arrayable or not. For default, it is `false`.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse PHPForge\\Html\\Helper\\Utils;\n\n$name = Utils::generateInputName('user', 'name');\n```\n\n### Sanitize content\n\nThe `Sanitize::class` helper can be used to sanitize HTML content.\n\nThe method accepts one parameter:\n\n- `content:` (...string|RenderInterface): The content to sanitize. It can be a string or an object that implements the\n  `RenderInterface::class`.  \n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse PHPForge\\Html\\Helper\\Sanitize;\n\n$content = Sanitize::html('\u003cscript\u003ealert(\"Hello, World!\")\u003c/script\u003e');\n```\n\n### Render HTML attributes\n\nThe `Attributes::class` helper can be used to `render` HTML attributes in a programmatic way.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse PHPForge\\Html\\Helper\\Attributes;\n\n$attributes = Attributes::render(\n    [\n        'class' =\u003e 'btn btn-primary',\n        'id' =\u003e 'submit-button',\n        'disabled' =\u003e true,\n    ]\n);\n```\n\n### Render Template\n\nThe `Template::class` helper can be used to render a template.\n\nThe method accepts two parameters:\n\n- `template:` (string): The template to render.\n- `tokenValues:` (array): The token values to replace in the template.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse PHPForge\\Html\\Helper\\Template;\n\n$template = '{{prefix}}\\n{{tag}}\\n{{suffix}}';\n$tokenValues = [\n    '{{prefix}}' =\u003e 'prefix',\n    '{{tag}}' =\u003e '\u003cdiv\u003econtent\u003c/div\u003e',\n    '{{suffix}}' =\u003e 'suffix',\n];\n\n$content = Template::render($template, $tokenValues);\n```\n\n\u003e `\\n` is a new line character, and it is used to separate the tokens in the template.\n\n### Validate value in list\n\nThe `Validator::class` helper can be used to validate a value in a list.\n\nThe method accepts tree parameters:\n\n- `value:` (mixed): The value to validate.\n- `exceptionMessage:` (string): The exception message to throw if the value is not in the list.\n- `list:` (...string): The list to validate the value.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse PHPForge\\Html\\Helper\\Validator;\n\n$value = Validator::inList('php', 'The value is not in the list.', 'php', 'javascript', 'typescript');\n```\n\n### Validate value iterable\n\nThe `Validator::class` helper can be used to validate an iterable value. If the value is not iterable or `null`, the\nmethod will throw an `InvalidArgumentException`.\n\nThe method accepts one parameter:\n\n- `value:` (mixed): The value to validate.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse PHPForge\\Html\\Helper\\Validator;\n\n$value = Validator::iterable([1, 2, 3]);\n```\n\n### Validate value numeric\n\nThe `Validator::class` helper can be used to validate a numeric value. If the value is not numeric or `null`, the method\nwill throw an `InvalidArgumentException`.\n\nThe method accepts one parameter:\n\n- `value:` (mixed): The value to validate.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse PHPForge\\Html\\Helper\\Validator;\n\n$value = Validator::numeric(1);\n```\n\n### Validate value scalar\n\nThe `Validator::class` helper can be used to validate a scalar value. If the value is not scalar or `null`, the method\nwill throw an `InvalidArgumentException`.\n\nThe method accepts one parameter:\n\n- `value:` (...mixed): The value to validate.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse PHPForge\\Html\\Helper\\Validator;\n\n$value = Validator::scalar('Hello, World!');\n```\n\n### Validate value string\n\nThe `Validator::class` helper can be used to validate a string value. If the value is not a string or `null`, the method\nwill throw an `InvalidArgumentException`.\n\nThe method accepts one parameter:\n\n- `value:` (mixed): The value to validate.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse PHPForge\\Html\\Helper\\Validator;\n\n$value = Validator::string('Hello, World!');\n```\n\n## Testing\n\n[Check the documentation testing](docs/testing.md) to learn about testing.\n\n## Support versions\n\n[![PHP81](https://img.shields.io/badge/PHP-%3E%3D8.1-787CB5)](https://www.php.net/releases/8.1/en.php)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE) for more information.\n\n## Our social networks\n\n[![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter\u0026logoColor=1DA1F2\u0026labelColor=555555?style=flat)](https://twitter.com/Terabytesoftw)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-forge%2Fhtml-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-forge%2Fhtml-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-forge%2Fhtml-helper/lists"}