{"id":21848915,"url":"https://github.com/scotteh/php-dom-wrapper","last_synced_at":"2026-03-02T11:04:42.047Z","repository":{"id":31535919,"uuid":"35100484","full_name":"scotteh/php-dom-wrapper","owner":"scotteh","description":"Simple DOM wrapper library to manipulate and traverse HTML documents similar to jQuery","archived":false,"fork":false,"pushed_at":"2024-11-18T12:05:46.000Z","size":196,"stargazers_count":146,"open_issues_count":4,"forks_count":34,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-29T09:13:02.365Z","etag":null,"topics":["autoloader","composer","dom","dom-wrapper-library","html","manipulation","parser","php","php-dom-wrapper","traversal","traverse-html-documents"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scotteh.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":"2015-05-05T13:14:31.000Z","updated_at":"2025-05-21T05:15:54.000Z","dependencies_parsed_at":"2025-03-05T17:01:03.094Z","dependency_job_id":null,"html_url":"https://github.com/scotteh/php-dom-wrapper","commit_stats":{"total_commits":152,"total_committers":11,"mean_commits":"13.818181818181818","dds":0.08552631578947367,"last_synced_commit":"edf37231a9ee609ea947ffaa5ac342a372f18b29"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"purl":"pkg:github/scotteh/php-dom-wrapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scotteh%2Fphp-dom-wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scotteh%2Fphp-dom-wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scotteh%2Fphp-dom-wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scotteh%2Fphp-dom-wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scotteh","download_url":"https://codeload.github.com/scotteh/php-dom-wrapper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scotteh%2Fphp-dom-wrapper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29999251,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-02T09:59:02.300Z","status":"ssl_error","status_checked_at":"2026-03-02T09:59:02.001Z","response_time":60,"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":["autoloader","composer","dom","dom-wrapper-library","html","manipulation","parser","php","php-dom-wrapper","traversal","traverse-html-documents"],"created_at":"2024-11-28T00:09:25.982Z","updated_at":"2026-03-02T11:04:42.021Z","avatar_url":"https://github.com/scotteh.png","language":"PHP","readme":"# PHP DOM Wrapper\n\n## Intro\n\nPHP DOM Wrapper is a simple DOM wrapper library to manipulate and traverse HTML documents. Based around jQuery's manipulation and traversal methods, largely mimicking the behaviour of it's jQuery counterparts.\n\n## Author\n\n - Andrew Scott (andrew@andrewscott.net.au)\n\n## Requirements\n\n - PHP 8.0 or later\n - PSR-4 compatible autoloader\n\n## Install\n\nInstall with [Composer](https://getcomposer.org/doc/).\n\n```\ncomposer require scotteh/php-dom-wrapper\n```\n\n## Autoloading\n\nThis library requires an autoloader, if you aren't already using one you can include [Composers autoloader](https://getcomposer.org/doc/01-basic-usage.md#autoloading).\n\n``` php\nrequire 'vendor/autoload.php';\n```\n\n## Methods\n\n### Manipulation\n\n| Method | jQuery Equivalent *(if different)* |\n|--------|------------------------------|\n| [addClass()](#addClass)    |\n| [follow()](#follow)       | *after()* |\n| [appendWith()](#appendWith)      | *append()* |\n| [appendTo()](#appendTo)    |\n| [attr()](#attr)        |\n| [clone()](#clone)       |\n| [destroy()](#destroy)      | *remove()* |\n| [detach()](#detach)      |\n| [empty()](#empty)       |\n| [hasClass()](#hasClass)    |\n| [html()](#html)        |\n| [precede()](#precede)      | *before()* |\n| [prependWith()](#prependWith)     | *prepend()* |\n| [prependTo()](#prependTo)   |\n| [removeAttr()](#removeAttr)  |\n| [removeClass()](#removeClass) |\n| [substituteWith()](#substituteWith) | *replaceWith()* |\n| [text()](#text)        |\n| [unwrap()](#unwrap)      |\n| [wrap()](#wrap)        |\n| [wrapAll()](#wrapAll)     |\n| [wrapInner()](#wrapInner)   |\n\n### Traversal\n\n| Method | jQuery Equivalent *(if different)* |\n|--------|------------------------------|\n| [add()](#add)          |\n| [children()](#children)     |\n| [closest()](#closest)      |\n| [contents()](#contents)     |\n| [eq()](#eq)           |\n| [filter()](#filter)       |\n| [find()](#find)         |\n| [first()](#first)        |\n| [has()](#has)          |\n| [is()](#is)           |\n| [last()](#last)         |\n| [map()](#map)          |\n| [following()](#following)         | *next()* |\n| [followingAll()](#followingAll)      | *nextAll()* |\n| [followingUntil()](#followingUntil)    | *nextUntil()* |\n| [not()](#not)          |\n| [parent()](#parent)       |\n| [parents()](#parents)      |\n| [parentsUntil()](#parentsUntil) |\n| [preceding()](#preceding)         | *prev()* |\n| [precedingAll()](#precedingAll)      | *prevAll()* |\n| [precedingUntil()](#precedingUntil)    | *prevUntil()* |\n| [siblings()](#siblings)     |\n| [slice()](#slice)        |\n\n### Other\n\n| Method | jQuery Equivalent *(if different)* |\n|--------|------------------------------|\n| [count()](#count)        | *length* (property) |\n| [each()](#each)\n\n## Usage\n\nExample #1:\n``` php\nuse DOMWrap\\Document;\n\n$html = '\u003cul\u003e\u003cli\u003eFirst\u003c/li\u003e\u003cli\u003eSecond\u003c/li\u003e\u003cli\u003eThird\u003c/li\u003e\u003c/ul\u003e';\n\n$doc = new Document();\n$doc-\u003ehtml($html);\n$nodes = $doc-\u003efind('li');\n\n// Returns '3'\nvar_dump($nodes-\u003ecount());\n\n// Append as a child node to each \u003cli\u003e\n$nodes-\u003eappendWith('\u003cb\u003e!\u003c/b\u003e');\n\n// Returns: \u003chtml\u003e\u003cbody\u003e\u003cul\u003e\u003cli\u003eFirst\u003cb\u003e!\u003c/b\u003e\u003c/li\u003e\u003cli\u003eSecond\u003cb\u003e!\u003c/b\u003e\u003c/li\u003e\u003cli\u003eThird\u003cb\u003e!\u003c/b\u003e\u003c/li\u003e\u003c/ul\u003e\u003c/body\u003e\u003c/html\u003e\nvar_dump($doc-\u003ehtml());\n```\n\n---\n\n## Methods\n\n### Manipulation\n\n#### addClass\n\n```\nself addClass(string|callable $class)\n```\n\n##### Example\n\n```php\n$doc = (new Document())-\u003ehtml('\u003cp\u003efirst paragraph\u003c/p\u003e\u003cp\u003esecond paragraph\u003c/p\u003e');\n$doc-\u003efind('p')-\u003eaddClass('text-center');\n```\n\n*Result:*\n\n``` html\n\u003cp class=\"text-center\"\u003efirst paragraph\u003c/p\u003e\u003cp class=\"text-center\"\u003esecond paragraph\u003c/p\u003e\n```\n\n---\n\n#### follow\n\n```\nself follow(string|NodeList|\\DOMNode|callable $input)\n```\n\nInsert the argument as a sibling directly after each of the nodes operated on.\n\n##### Example\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cul\u003e\u003cli\u003efirst\u003c/li\u003e\u003cli\u003esecond\u003c/li\u003e\u003c/ul\u003e');\n$doc-\u003efind('li')-\u003efirst()-\u003efollow('\u003cli\u003efirst-and-a-half\u003c/li\u003e');\n\n```\n\n*Result:*\n\n``` html\n\u003cul\u003e\n    \u003cli\u003efirst\u003c/li\u003e\n    \u003cli\u003efirst-and-a-half\u003c/li\u003e\n    \u003cli\u003esecond\u003c/li\u003e\n\u003c/ul\u003e\n```\n\n---\n\n#### appendWith\n\n```\nself appendWith(string|NodeList|\\DOMNode|callable $input)\n```\n\n##### Example\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cdiv\u003eThe quick brown fox jumps over the lazy dog\u003c/div\u003e');\n$doc-\u003efind('div')-\u003eappendWith('\u003cstrong\u003e Appended!\u003c/strong\u003e');\n```\n\n*Result:*\n\n``` html\n\u003cdiv\u003eThe quick brown fox jumps over the lazy dog\u003cstrong\u003e Appended!\u003c/strong\u003e\u003c/div\u003e\n```\n\n---\n\n#### appendTo\n\n```\nself appendTo(string|NodeList|\\DOMNode $selector)\n```\n\n##### Example\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cdiv\u003eThe quick brown fox jumps over the lazy dog\u003c/div\u003e');\n$doc-\u003ecreate('\u003cstrong\u003e Appended!\u003c/strong\u003e')-\u003eappendTo('div');\n```\n\n*Result:*\n``` html\n\u003cdiv\u003eThe quick brown fox jumps over the lazy dog\u003cstrong\u003e Appended!\u003c/strong\u003e\u003c/div\u003e\n```\n\n---\n\n#### attr\n\n```\nself|string attr(string $name[, mixed $value = null])\n```\n\n##### Example #1 (Set)\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cdiv class=\"text-center\"\u003e\u003c/div\u003e');\n$doc-\u003eattr('class', 'text-left');\n```\n\n*Result:*\n\n``` html\n\u003cdiv class=\"text-left\"\u003e\u003c/div\u003e\n```\n\n##### Example #2 (Get)\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cdiv class=\"text-center\"\u003e\u003c/div\u003e');\necho $doc-\u003eattr('text-center');\n```\n\n*Result:*\n\n``` html\ntext-center\n```\n\n---\n\n#### precede\n\n```\nself precede(string|NodeList|\\DOMNode|callable $input)\n```\n\nInsert the argument as a sibling just before each of the nodes operated on.\n\n##### Example\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cul\u003e\u003cli\u003efirst\u003c/li\u003e\u003cli\u003esecond\u003c/li\u003e\u003c/ul\u003e');\ndoc-\u003efind('li')-\u003efirst()-\u003eprecede('\u003cli\u003ezeroth\u003c/li\u003e');\n```\n\n*Result:*\n\n``` html\n\u003cul\u003e\n    \u003cli\u003ezeroth\u003c/li\u003e\n    \u003cli\u003efirst\u003c/li\u003e\n    \u003cli\u003esecond\u003c/li\u003e\n\u003c/ul\u003e\n```\n\n---\n\n#### clone\n\n```\nNodeList|\\DOMNode clone()\n```\n\n##### Example\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cul\u003e\u003cli\u003eItem\u003c/li\u003e\u003c/ul\u003e');\n$doc-\u003efind('div')-\u003eclone()-\u003eappendTo('ul'); \n```\n\n*Result:*\n\n``` html\n\u003cul\u003e\u003cli\u003eItem\u003c/li\u003e\u003cli\u003eItem\u003c/li\u003e\u003c/ul\u003e\n```\n\n---\n\n#### destroy\n\n```\nself destroy([string $selector = null])\n```\n\n##### Example\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cul\u003e\u003cli class=\"first\"\u003e\u003c/li\u003e\u003cli class=\"second\"\u003e\u003c/li\u003e\u003c/ul\u003e');\n$doc-\u003efind('.first')-\u003edestroy();\n```\n\n*Result:*\n``` html\n\u003cul\u003e\u003cli class=\"second\"\u003e\u003c/li\u003e\u003c/ul\u003e\n```\n\n---\n\n#### detach\n\n```\nNodeList detach([string $selector = null])\n```\n\n##### Example\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cul class=\"first\"\u003e\u003cli\u003eItem\u003c/li\u003e\u003c/ul\u003e\u003cul class=\"second\"\u003e\u003c/ul\u003e');\n$el = $doc-\u003efind('ul.first li')-\u003edetach();\n$doc-\u003efirst('ul.second').append($el); \n```\n\n*Result:*\n\n``` html\n\u003cul class=\"first\"\u003e\u003c/ul\u003e\u003cul class=\"second\"\u003e\u003cli\u003eItem\u003c/li\u003e\u003c/ul\u003e\n```\n\n---\n\n#### empty\n\n```\nself empty()\n```\n\n##### Example\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cdiv\u003eThe quick brown fox jumps over the lazy dog\u003c/div\u003e');\n$doc-\u003efind('div')-\u003eempty(); \n```\n\n*Result:*\n\n``` html\n\u003cdiv\u003e\u003c/div\u003e\n```\n\n---\n\n#### hasClass\n\n```\nbool hasClass(string $class)\n```\n\n##### Example\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cdiv class=\"text-center\"\u003e\u003c/div\u003e');\necho $doc-\u003efirst('div')-\u003ehasClass('text-center');\n```\n\n*Result:*\n\n``` html\ntrue\n```\n\n---\n\n#### html\n\n```\nstring|self html([string|NodeList|\\DOMNode|callable $input = null])\n```\n\n##### Example #1 (Set)\n\n``` php\n$doc = (new Document());\n$doc-\u003ehtml('\u003cdiv class=\"example\"\u003e\u003c/div\u003e');\n```\n\n*Result:*\n\n``` html\n\u003cdiv class=\"example\"\u003e\u003c/div\u003e\n```\n\n##### Example #1 (Get)\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cdiv class=\"example\"\u003e\u003c/div\u003e');\n$doc-\u003efind('div')-\u003eappendWith('\u003cspan\u003eExample!\u003c/span\u003e');\necho $doc-\u003ehtml();\n```\n\n*Result:*\n\n``` html\n\u003cdiv class=\"example\"\u003e\u003cspan\u003eExample!\u003c/span\u003e\u003c/div\u003e\n```\n\n---\n\n#### prependWith\n\n```\nself prependWith(string|NodeList|\\DOMNode|callable $input)\n```\n\n##### Example\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cdiv\u003eThe quick brown fox jumps over the lazy dog\u003c/div\u003e');\n$doc-\u003efind('div')-\u003eprependWith('\u003cstrong\u003ePrepended! \u003c/strong\u003e');\n```\n\n*Result:*\n\n``` html\n\u003cdiv\u003e\u003cstrong\u003ePrepended! \u003c/strong\u003eThe quick brown fox jumps over the lazy dog\u003c/div\u003e\n```\n\n---\n\n#### prependTo\n\n```\nself prependTo(string|NodeList|\\DOMNode $selector)\n```\n\n##### Example\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cdiv\u003eThe quick brown fox jumps over the lazy dog\u003c/div\u003e');\n$doc-\u003ecreate('\u003cstrong\u003ePrepended! \u003c/strong\u003e')-\u003eappendTo('div');\n```\n\n*Result:*\n``` html\n\u003cdiv\u003e\u003cstrong\u003ePrepended! \u003c/strong\u003eThe quick brown fox jumps over the lazy dog\u003c/div\u003e\n```\n\n---\n\n#### removeAttr\n\n```\nself removeAttr(string $name)\n```\n\n##### Example\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cdiv class=\"first second\"\u003e\u003c/div\u003e');\n$doc-\u003efind('div').removeAttr('class');\n```\n\n*Result:*\n``` html\n\u003cdiv\u003e\u003c/div\u003e\n```\n\n---\n\n#### removeClass\n\n```\nself removeClass(string|callable $class)\n```\n\n##### Example\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cdiv class=\"first second\"\u003e\u003c/div\u003e');\n$doc-\u003efind('div').removeClass('first');\n```\n\n*Result:*\n``` html\n\u003cdiv class=\"second\"\u003e\u003c/div\u003e\n```\n\n---\n\n#### substituteWith\n\n```\nself substituteWith(string|NodeList|\\DOMNode|callable $input)\n```\n\nReplace each node in the current set with the contents provided.\n\n##### Example\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cp\u003e\u003cb\u003eHello\u003c/b\u003e \u003cb\u003eWorld!\u003c/b\u003e\u003c/p\u003e');\n$doc-\u003efind('b')-\u003esubstituteWith(function($node) {\n    return '\u003cem\u003e' . $node-\u003etext() . '\u003c/em\u003e';\n});\necho $doc-\u003ehtml();\n```\n\n*Result:*\n``` html\n\u003cp\u003e\u003cem\u003eHello\u003c/em\u003e \u003cem\u003eWorld!\u003c/em\u003e\u003c/p\u003e\n```\n\n---\n\n#### text\n\n```\nstring|self text([string|NodeList|\\DOMNode|callable $input = null])\n```\n\nGet the text contents of the current set.\n\n##### Example (get)\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cdiv class=\"text\"\u003eHello World!\u003c/div\u003e');\necho $doc-\u003efind('.text')-\u003etext();\n```\n\n*Result:*\n``` html\nHello World!\n```\n\nSet the text contents for current set.\n\n##### Example (set)\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cdiv class=\"text\"\u003e\u003cstring\u003eThe quick brown\u003c/strong\u003e fox \u003cem\u003ejumps over the lazy dog\u003c/em\u003e\u003c/div\u003e');\n$doc-\u003efind('.text')-\u003etext('Hello World!');\necho $doc-\u003ehtml();\n```\n\n*Result:*\n``` html\n\u003cdiv class=\"text\"\u003eHello World!\u003c/div\u003e\n```\n\n---\n\n#### unwrap\n\n```\nself unwrap()\n```\n\nUnwrap each current node by removing its parent, replacing the parent\nwith its children (i.e. the current node and its siblings).\n\nNote that each node is operated on separately, so when you call\n`unwrap()` on a `NodeList` containing two siblings, *two* parents will\nbe removed.\n\n##### Example\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cdiv id=\"outer\"\u003e\u003cdiv id=\"first\"/\u003e\u003cdiv id=\"second\"/\u003e\u003c/div\u003e');\n$doc-\u003efind('#first')-\u003eunwrap();\n```\n\n*Result:*\n\n``` html\n\u003cdiv id=\"first\"\u003e\u003c/div\u003e\n\u003cdiv id=\"second\"\u003e\u003c/div\u003e\n```\n\n---\n\n#### wrap\n\n```\nself wrap(string|NodeList|\\DOMNode|callable $input)\n```\n\nWrap the current node or nodes in the given structure.\n\nThe wrapping structure can be nested, but should only contain one node\non each level (any extra siblings are removed). The outermost node\nreplaces the node operated on, while the node operated on is put into\nthe innermost node.\n\nIf called on a `NodeList`, each of nodes in the list will be separately\nwrapped. When such a list contains multiple nodes, the argument to\nwrap() cannot be a `NodeList` or `\\DOMNode`, since those can be used\nto wrap a node only once. A string or callable returning a string or a\nunique `NodeList` or `\\DomNode` every time can be used in this case.\n\nWhen a callable is passed, it is called once for each node operated on,\npassing that node and its index. The callable should return either a\nstring, or a unique `NodeList` or `\\DOMNode` ever time it is called.\n\nNote that this returns the original node like all other methods, not the\n(new) node(s) wrapped around it.\n\n##### Example\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cspan\u003efoo\u003cspan\u003e\u003cspan\u003ebar\u003c/span\u003e');\n$doc-\u003efind-\u003e('span')-\u003ewrap('\u003cdiv\u003e\u003cp/\u003e\u003c/div\u003e');\n```\n\n*Result:*\n\n``` html\n\u003cdiv\u003e\u003cp\u003e\u003cspan\u003efoo\u003c/span\u003e\u003c/p\u003e\u003c/div\u003e\n\u003cdiv\u003e\u003cp\u003e\u003cspan\u003ebar\u003c/span\u003e\u003c/p\u003e\u003c/div\u003e\n```\n\n\n---\n\n#### wrapAll\n\n```\nself wrapAll(string|NodeList|\\DOMNode|callable $input)\n```\n\nLike [wrap()](#wrap), but when operating on multiple nodes, all of them\nwill be wrapped together in a single instance of the given structure,\nrather than each of them individually.\n\nNote that the wrapping structure replaces the first node operated on, so\nif the other nodes operated on are not siblings of the first, they will\nbe moved inside the document.\n\n##### Example\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cspan\u003efoo\u003cspan\u003e\u003cspan\u003ebar\u003c/span\u003e');\n$doc-\u003efind-\u003e('span')-\u003ewrapAll('\u003cdiv\u003e\u003cp/\u003e\u003c/div\u003e');\n```\n\n*Result:*\n\n``` html\n\u003cdiv\u003e\u003cp\u003e\n    \u003cspan\u003efoo\u003c/span\u003e\n    \u003cspan\u003ebar\u003c/span\u003e\n\u003c/p\u003e\u003c/div\u003e\n```\n\n---\n\n#### wrapInner\n\n```\nself wrapInner(string|NodeList|\\DOMNode|callable $input)\n```\n\nLike [wrap()](#wrap), but rather than wrapping the nodes that are being\noperated on, this wraps their contents.\n\n##### Example\n\n``` php\n$doc = (new Document())-\u003ehtml('\u003cspan\u003efoo\u003cspan\u003e\u003cspan\u003ebar\u003c/span\u003e');\n$doc-\u003efind('span')-\u003ewrapInner('\u003cb\u003e\u003ci/\u003e\u003c/b\u003e');\n```\n\n*Result:*\n\n``` html\n\u003cspan\u003e\u003cb\u003e\u003ci\u003efoo\u003c/i\u003e\u003c/b\u003e\u003c/span\u003e\n\u003cspan\u003e\u003cb\u003e\u003ci\u003ebar\u003c/i\u003e\u003c/b\u003e\u003c/span\u003e\n```\n\n---\n\n\n### Traversal\n\n#### add\n\n```\nNodeList add(string|NodeList|\\DOMNode $input)\n```\n    \nAdd additional node(s) to the existing set.\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('a');\n$nodes-\u003eadd($doc-\u003efind('p'));\n```\n\n---\n\n#### children\n\n```\nNodeList children()\n```\n    \nReturn all children of each element node in the current set.\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('p');\n$childrenOfParagraphs = $nodes-\u003echildren();\n```\n\n---\n\n#### closest\n\n```\nElement|NodeList|null closest(string|NodeList|\\DOMNode|callable $input)\n```\n    \nReturn the first element matching the supplied input by traversing up through the ancestors of each node in the current set. \n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('a');\n$closestAncestors = $nodes-\u003eclosest('p');\n```\n\n---\n\n#### contents\n\n```\nNodeList contents()\n```\n    \nReturn all children of each node in the current set.\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('p');\n$contents = $nodes-\u003econtents();\n```\n\n---\n\n#### eq\n\n```\n\\DOMNode|null eq(int $index)\n```\n    \nReturn node in the current set at the specified index.\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('a');\n$nodeAtIndexOne = $nodes-\u003eeq(1);\n```\n\n---\n\n#### filter\n\n```\nNodeList filter(string|NodeList|\\DOMNode|callable $input)\n```\n    \nReturn nodes in the current set that match the input. \n\n##### Example\n\n``` php\n$nodes = $doc-\u003efilter('a')\n$exampleATags = $nodes-\u003efilter('[href*=https://example.org/]');\n```\n\n---\n\n#### find\n\n```\nNodeList find(string $selector[, string $prefix = 'descendant::'])\n```\n    \nReturn the decendants of the current set filtered by the selector and optional XPath axes.\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('a');\n```\n\n---\n\n#### first\n\n```\nmixed first()\n```\n    \nReturn the first node of the current set.\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('a');\n$firstNode = $nodes-\u003efirst();\n```\n\n---\n\n#### has\n\n```\nNodeList has(string|NodeList|\\DOMNode|callable $input)\n```\n    \nReturn nodes with decendants of the current set matching the input. \n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('a');\n$anchorTags = $nodes-\u003ehas('span');\n```\n\n---\n\n#### is\n\n```\nbool is(string|NodeList|\\DOMNode|callable $input)\n```\n    \nTest if nodes from the current set match the input. \n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('a');\n$isAnchor = $nodes-\u003eis('[anchor]');\n```\n\n---\n\n#### last\n\n```\nmixed last()\n```\n    \nReturn the last node of the current set.\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('a');\n$lastNode = $nodes-\u003elast();\n```\n\n---\n\n#### map\n\n```\nNodeList map(callable $function)\n```\n    \nApply a callback to nodes in the current set and return a new NodeList.\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('a');\n$nodeValues = $nodes-\u003emap(function($node) {\n    return $node-\u003enodeValue;\n});\n```\n\n---\n\n#### following\n\n```\n\\DOMNode|null following([string|NodeList|\\DOMNode|callable $selector = null])\n```\n    \nReturn the sibling immediately following each element node in the current set. \n\n*Optionally filtered by selector.*\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('a');\n$follwingNodes = $nodes-\u003efollowing();\n```\n\n---\n\n#### followingAll\n\n```\nNodeList followingAll([string|NodeList|\\DOMNode|callable $selector = null])\n```\n    \nReturn all siblings following each element node in the current set.\n\n*Optionally filtered by selector.*\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('a');\n$follwingAllNodes = $nodes-\u003efollowingAll('[anchor]');\n```\n\n---\n\n#### followingUntil\n\n```\nNodeList followingUntil([[string|NodeList|\\DOMNode|callable $input = null], string|NodeList|\\DOMNode|callable $selector = null])\n```\n    \nReturn all siblings following each element node in the current set upto but not including the node matched by $input.\n\n*Optionally filtered by input.*\u003cbr\u003e\n*Optionally filtered by selector.*\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('a');\n$follwingUntilNodes = $nodes-\u003efollowingUntil('.submit');\n```\n\n---\n\n#### not\n\n```\nNodeList not(string|NodeList|\\DOMNode|callable $input)\n```\n    \nReturn element nodes from the current set not matching the input. \n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('a');\n$missingHrefAttribute = $nodes-\u003enot('[href]');\n```\n\n---\n\n#### parent\n\n```\nElement|NodeList|null parent([string|NodeList|\\DOMNode|callable $selector = null])\n```\n    \nReturn the immediate parent of each element node in the current set. \n\n*Optionally filtered by selector.*\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('a');\n$parentNodes = $nodes-\u003eparent();\n```\n\n---\n\n#### parents\n\n```\nNodeList parent([string $selector = null])\n```\n    \nReturn the ancestors of each element node in the current set. \n\n*Optionally filtered by selector.*\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('a');\n$ancestorDivNodes = $nodes-\u003eparents('div');\n```\n\n---\n\n#### parentsUntil\n\n```\nNodeList parentsUntil([[string|NodeList|\\DOMNode|callable $input, [string|NodeList|\\DOMNode|callable $selector = null])\n```\n    \nReturn the ancestors of each element node in the current set upto but not including the node matched by $selector.\n\n*Optionally filtered by input.*\u003cbr\u003e\n*Optionally filtered by selector.*\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('a');\n$ancestorDivNodes = $nodes-\u003eparentsUntil('div');\n```\n\n---\n\n#### preceding\n\n```\n\\DOMNode|null preceding([string|NodeList|\\DOMNode|callable $selector = null])\n```\n    \nReturn the sibling immediately preceding each element node in the current set. \n\n*Optionally filtered by selector.*\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('a');\n$precedingNodes = $nodes-\u003epreceding();\n```\n\n---\n\n#### precedingAll\n\n```\nNodeList precedingAll([string|NodeList|\\DOMNode|callable $selector = null])\n```\n    \nReturn all siblings preceding each element node in the current set.\n\n*Optionally filtered by selector.*\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('a');\n$precedingAllNodes = $nodes-\u003eprecedingAll('[anchor]');\n```\n\n---\n#### precedingUntil\n\n```\nNodeList precedingUntil([[string|NodeList|\\DOMNode|callable $input = null], string|NodeList|\\DOMNode|callable $selector = null])\n```\n    \nReturn all siblings preceding each element node in the current set upto but not including the node matched by $input.\n\n*Optionally filtered by input.*\u003cbr\u003e\n*Optionally filtered by selector.*\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('a');\n$precedingUntilNodes = $nodes-\u003eprecedingUntil('.submit');\n```\n\n---\n\n#### siblings\n\n```\nNodeList siblings([[string|NodeList|\\DOMNode|callable $selector = null])\n```\n    \nReturn siblings of each element node in the current set.\n\n*Optionally filtered by selector.*\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('p');\n$siblings = $nodes-\u003esiblings();\n```\n\n---\n\n#### slice\n\n```\nNodeList slice(int $start[, int $end])\n```\n    \nReturn a subset of the current set based on the start and end indexes.\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('p');\n// Return nodes 1 through to 3 as a new NodeList\n$slicedNodes = $nodes-\u003eslice(1, 3);\n```\n\n---\n\n### Additional Methods\n\n#### count\n\n```\nint count()\n```\n\nReturn number of nodes in the current set\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('p');\n\necho $nodes-\u003ecount();\n```\n\n---\n\n#### each\n\n```\nself each(callable $function)\n```\n\nIterate through for each item in the existing set via callback\n\n##### Example\n\n``` php\n$nodes = $doc-\u003efind('p');\n\n$nodes-\u003eeach(function($node){\n    echo $node-\u003enodeName . \"\\n\";\n});\n```\n\n## Licensing\n\nPHP DOM Wrapper is licensed by Andrew Scott under the BSD 3-Clause License, see the LICENSE file for more details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscotteh%2Fphp-dom-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscotteh%2Fphp-dom-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscotteh%2Fphp-dom-wrapper/lists"}