{"id":18659095,"url":"https://github.com/devvoh/simpledom","last_synced_at":"2025-11-06T00:30:41.500Z","repository":{"id":56967141,"uuid":"115826642","full_name":"devvoh/simpledom","owner":"devvoh","description":"SimpleDom adds simple class manipulation to DOMDocuments and DOMElements.","archived":false,"fork":false,"pushed_at":"2017-12-31T09:31:28.000Z","size":10,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-03-15T09:02:52.943Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/devvoh.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}},"created_at":"2017-12-30T21:54:25.000Z","updated_at":"2020-04-25T04:10:53.000Z","dependencies_parsed_at":"2022-08-21T11:20:23.021Z","dependency_job_id":null,"html_url":"https://github.com/devvoh/simpledom","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devvoh%2Fsimpledom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devvoh%2Fsimpledom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devvoh%2Fsimpledom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devvoh%2Fsimpledom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devvoh","download_url":"https://codeload.github.com/devvoh/simpledom/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239477266,"owners_count":19645320,"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":[],"created_at":"2024-11-07T07:35:44.421Z","updated_at":"2025-11-06T00:30:41.451Z","avatar_url":"https://github.com/devvoh.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimpleDom\n\n[![Build Status](https://travis-ci.org/devvoh/simpledom.svg?branch=master)](https://travis-ci.org/devvoh/simpledom)\n[![Latest Stable Version](https://poser.pugx.org/devvoh/simpledom/v/stable)](https://packagist.org/packages/devvoh/simpledom)\n[![Latest Unstable Version](https://poser.pugx.org/devvoh/simpledom/v/unstable)](https://packagist.org/packages/devvoh/simpledom)\n[![License](https://poser.pugx.org/devvoh/simpledom/license)](https://packagist.org/packages/devvoh/simpledom)\n\nSimpleDom adds simple class manipulation to DOMDocuments and DOMElements.\n\n## Requirements\n\n- PHP 5.6+\n- Composer\n\n## Installation\n\nSimpleDom can be installed by using [Composer](http://getcomposer.org/). Simply run:\n\n`composer require devvoh/simpledom`\n\n## Usage\n\nSimpleDom can be considered a facade adapter for the built-in `DOMDocument` and `DOMElement` classes. As such, you can use them anywhere you currently use those.\n\nCreating a new instance is done with an extra step, however:\n\n```php\n$domDocument = new \\DOMDocument();\n$domDocument-\u003eloadHTML($htmlString);\n\n$document = \\SimpleDom\\Document::fromDOMDocument($domDocument);\n```\n\nTo then get all elements with the class \"header\":\n\n```php\n$elements = $document-\u003egetElementsByClassName(\"header\");\n```\n\nAnd you'll get an array of `\\SimpleDom\\Element` items. SimpleDom also overwrites the following `DOMDocument` methods: `getElementsByTagName()`, `getElementById()` and `createElement()`.\n\nNormally the `getElement` methods would return a `DOMNodeList` but SimpleDom returns an array of elements instead.\n\nIt's also possible to get elements which have multiple classes.\n\n```php\n$elements = $document-\u003egetElementsByClassNames([\"header\", \"sub\"]);\n```\n\nWhich will only return items that have both the \"header\" and \"sub\" class. The order of which is not important.\n\nTo get the DOMDocument back so you can save the HTML, simply do this:\n\n```php\n$domDocument = $document-\u003egetDOMDocument();\necho $domDocument-\u003esaveHTML();\n```\n\nSimpleDom `Element` instances have some added features as well.\n\n```php\n$element = $document-\u003ecreateElement(\"span\", \"this is a span!\");\n$element-\u003eaddClass(\"blue\");\n```\n\nThe above code will result in the following html: `\u003cspan class=\"blue\"\u003ethis is a span!\u003c/span\u003e`\n\nThe following methods are available to work with classes and Elements:\n- `getClasses(): array`\n- `setClasses(array): Element`\n- `hasClass(string): bool`\n- `hasClasses(array): bool`\n- `addClass(string): Element`\n- `addClasses(array): Element`\n- `removeClass(string): Element`\n- `removeClasses(array): Element`\n- `toggleClass(string): Element`\n- `toggleClasses(array): Element`\n- `clearClasses(): Element`\n\n## Contact\n\nAll questions can be asked through github. Just create an issue and I'll get back with an answer as soon as possible.\n\n## License\n\nDevvoh SimpleDom is open-sourced software licensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevvoh%2Fsimpledom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevvoh%2Fsimpledom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevvoh%2Fsimpledom/lists"}