{"id":15693709,"url":"https://github.com/mcaskill/php-html-build-attributes","last_synced_at":"2025-07-03T07:06:39.710Z","repository":{"id":62526070,"uuid":"343837439","full_name":"mcaskill/php-html-build-attributes","owner":"mcaskill","description":"Generate a string of HTML attributes.","archived":false,"fork":false,"pushed_at":"2023-08-10T02:11:54.000Z","size":29,"stargazers_count":7,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"1.x","last_synced_at":"2025-06-28T12:06:17.018Z","etag":null,"topics":["html","php","utility","utility-function"],"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/mcaskill.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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":"2021-03-02T16:22:32.000Z","updated_at":"2024-01-08T04:28:06.000Z","dependencies_parsed_at":"2024-10-24T01:15:32.862Z","dependency_job_id":"5b52cc8d-f1f7-4047-bc48-b47d3922f743","html_url":"https://github.com/mcaskill/php-html-build-attributes","commit_stats":{"total_commits":33,"total_committers":3,"mean_commits":11.0,"dds":0.5454545454545454,"last_synced_commit":"42f34e22781857dc9d9bd8c1c8330c893bcc4066"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/mcaskill/php-html-build-attributes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcaskill%2Fphp-html-build-attributes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcaskill%2Fphp-html-build-attributes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcaskill%2Fphp-html-build-attributes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcaskill%2Fphp-html-build-attributes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcaskill","download_url":"https://codeload.github.com/mcaskill/php-html-build-attributes/tar.gz/refs/heads/1.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcaskill%2Fphp-html-build-attributes/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262428445,"owners_count":23309440,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["html","php","utility","utility-function"],"created_at":"2024-10-03T18:47:44.542Z","updated_at":"2025-07-03T07:06:39.682Z","avatar_url":"https://github.com/mcaskill.png","language":"PHP","readme":"# html_build_attributes\n\n\u003e PHP 5 \u003e= 5.4, PHP 7, PHP 8\n\nGenerate a string of HTML attributes.\n\n## Installation\n\nUsing [Composer](https://getcomposer.org/):\n\n```\n$ composer require mcaskill/php-html-build-attributes\n```\n\nAlternatively, download `Function.HTML-Build-Attributes.php` from the package\nsource and save the file into your project path somewhere.\n\n## Upgrading\n\nThis package follows [semantic versioning](https://semver.org/), which means\nbreaking changes may occur between major releases.\n\n## API\n\n```php\nhtml_build_attributes( array|object $attr [, callable $callback = null ] ) : string\n```\n\n### Parameters\n\n- `attr` — Associative array or object containing properties, representing\n  attribute names and values.\n  \n  If `attr` is a non-iterable object, then only accessible non-static properties\n  will be incorporated into the result.\n  \n  If an attribute name is an empty string, the attribute is ignored.\n  The attribute name will be trimmed of leading/trailing whitespace.\n  \n  If an attribute value is callable (either as a [`Closure`][class.closure] or\n  invokable), it is called and the returned value continues processing.\n  \n  If an attribute value is `null`, the attribute is ignored.\n  \n  If an attribute value is an arrayable or a stringable object, it is converted\n  to its primitive type.\n  \n  If an attribute value is a boolean and `true`, the attribute will be rendered\n  without a value, otherwise the attribute is ignored.\n  \n  If an attribute value is an array, only numbers and strings are accepted.\n  Strings of the array will be trimmed of leading/trailing whitespace.\n  If the filtered array is empty, the attribute is ignored.\n  \n  Any other value will be serialized using [`json_encode()`][function.json_encode].\n  \n- `callback` — Callback function to escape the values for HTML attributes.\n  \n  If no function is provided, [`htmlspecialchars()`][function.htmlspecialchars]\n  is used;\n  \n  If using WordPress, the [`esc_attr()`][wp.esc_attr] function is used.\n\n### Return Values\n\nReturns a string of HTML attributes or a empty string if `attr` is invalid or empty.\n\n## Examples\n\n### Example #1: Simple usage of html_build_attributes()\n\n```php\n$attr = [\n  'type'           =\u003e 'file',\n  'id'             =\u003e 'avatar',\n  'name'           =\u003e 'avatar',\n  'class'          =\u003e [ 'form-control', 'form-control-sm' ],\n  'multiple'       =\u003e true,\n  'disabled'       =\u003e false,\n  'accept'         =\u003e implode(',', [ 'image/png', 'image/jpeg' ]),\n  'data-max-files' =\u003e 3,\n];\n\necho '\u003cinput ' . html_build_attributes($attr) . '\u003e';\n```\n\nThe above example will output:\n\n```html\n\u003cinput type=\"file\" id=\"avatar\" name=\"avatar\" class=\"form-control form-control-sm\" multiple accept=\"image/png,image/jpeg\" data-max-files=\"3\"\u003e\n```\n\n[class.closure]:             https://php.net/class.closure\n[function.htmlspecialchars]: https://php.net/function.htmlspecialchars\n[function.json_encode]:      https://php.net/function.json_encode\n[object.invoke]:             https://php.net/oop5.magic#object.invoke\n[wp.esc_attr]:               https://developer.wordpress.org/reference/functions/esc_attr/\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcaskill%2Fphp-html-build-attributes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcaskill%2Fphp-html-build-attributes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcaskill%2Fphp-html-build-attributes/lists"}