{"id":26984613,"url":"https://github.com/dneustadt/html-tag-replace","last_synced_at":"2025-04-03T17:48:36.590Z","repository":{"id":56970416,"uuid":"115776819","full_name":"dneustadt/html-tag-replace","owner":"dneustadt","description":"Replace and enhance markup tags and/or attributes","archived":false,"fork":false,"pushed_at":"2019-10-22T14:49:23.000Z","size":6,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-18T09:10:17.606Z","etag":null,"topics":["attributes","dom","html","markup","replace","search","tags"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dneustadt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"dneustadt"}},"created_at":"2017-12-30T05:46:42.000Z","updated_at":"2019-10-22T14:49:26.000Z","dependencies_parsed_at":"2022-08-21T10:50:58.667Z","dependency_job_id":null,"html_url":"https://github.com/dneustadt/html-tag-replace","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dneustadt%2Fhtml-tag-replace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dneustadt%2Fhtml-tag-replace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dneustadt%2Fhtml-tag-replace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dneustadt%2Fhtml-tag-replace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dneustadt","download_url":"https://codeload.github.com/dneustadt/html-tag-replace/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247052501,"owners_count":20875681,"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":["attributes","dom","html","markup","replace","search","tags"],"created_at":"2025-04-03T17:48:36.032Z","updated_at":"2025-04-03T17:48:36.580Z","avatar_url":"https://github.com/dneustadt.png","language":"PHP","funding_links":["https://github.com/sponsors/dneustadt"],"categories":[],"sub_categories":[],"readme":"HtmlTagReplace\n=====\n[![Scrutinizer](https://scrutinizer-ci.com/g/dneustadt/html-tag-replace/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/dneustadt/html-tag-replace/?branch=master)\n[![Travis CI](https://travis-ci.org/dneustadt/html-tag-replace.svg?branch=master)](https://travis-ci.org/dneustadt/html-tag-replace)\n\na helper to replace and enhance html tags and their attributes.\n\n## Features\n\n* Append, prepend and switch tags.\n* Add custom attributes to tags\n* Switch, clone or remove attributes.\n\n## Usage\n\nCreate an Instance of `HtmlTagReplace` passing existing markup.\n\nUse `replaceTag` method of said instance passing the following arguments:\n\n* `search` Name of the tag to be replaced\n* `replace` Name of the new tag\n* `closingTag` (bool, default: false) defines whether searched tag has closing tag\n* `argumentsReplace` (array) key-value pairs (`search =\u003e replace`) of attributes to be replaced. Multidimensional (`search =\u003e array`) to clone value into multiple arguments.\n* `arguments` custom arguments injected\n* `append` injected after targeted tag\n* `prepend` injected before targeted tag\n\nYou can call the method `compress` to minify the markup.\n\nFinally retrieve the altered markup calling `getMarkup`\n\n## Example\n\n```php\n$markup = '\n    \u003cimg src=\"#\" alt=\"foo\"\u003e\n    \u003cimg src=\"#\"\u003e\n    \u003cdiv id=\"foo\"\u003ebar\u003c/div\u003e\n    \u003cem class=\"foo\"\u003ebar\u003c/em\u003e\n    \u003cinput type=\"text\" name=\"foo\"\u003e\n';\n  \n$replacer = new HtmlTagReplace($markup);\n  \necho $replacer-\u003ereplaceTag(\n        'img',\n        'a',\n        false,\n        ['src' =\u003e 'href', 'alt' =\u003e false],\n        'title=\"show image\"',\n        'show image\u003c/a\u003e'\n    )-\u003ereplaceTag(\n        'div',\n        'article',\n        true,\n        ['id' =\u003e 'class'],\n        null,\n        null,\n        '\u003chr\u003e'\n    )-\u003ereplaceTag(\n        'em',\n        'strong',\n        true\n    )-\u003ereplaceTag(\n        'input',\n        'input',\n        false,\n        ['name' =\u003e ['name', 'id']]\n    )-\u003ecompress()-\u003egetMarkup();\n```\n\nwill result in (not minified for readability):\n\n```html\n\u003ca title=\"show image\" href=\"#\"\u003eshow image\u003c/a\u003e\n\u003ca title=\"show image\" href=\"#\"\u003eshow image\u003c/a\u003e\n\u003chr\u003e\u003carticle class=\"foo\"\u003ebar\u003c/article\u003e\n\u003cstrong class=\"foo\"\u003ebar\u003c/strong\u003e\n\u003cinput type=\"text\" name=\"foo\" id=\"foo\"\u003e\n```\n\n# Todos\n\n* add more filter options for targeting tags\n* optimize method for filtering and replacing arguments\n* content manipulation\n* synchronized replacement","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdneustadt%2Fhtml-tag-replace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdneustadt%2Fhtml-tag-replace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdneustadt%2Fhtml-tag-replace/lists"}